-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtst.c
36 lines (30 loc) · 771 Bytes
/
tst.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
int main() {
const char *device_path = "/dev/input/event0";
int fd;
struct input_event ev;
fd = open(device_path, O_RDONLY);
if (fd == -1) {
perror("Unable to open device");
exit(EXIT_FAILURE);
}
while (1) {
if (read(fd, &ev, sizeof(struct input_event)) == -1) {
perror("Error reading event");
exit(EXIT_FAILURE);
}
if (ev.type == EV_ABS) {
if (ev.code == ABS_X) {
printf("X: %d ", ev.value);
} else if (ev.code == ABS_Y) {
printf("Y: %d\n", ev.value);
}
}
}
close(fd);
return 0;
}