-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathread_event.c
53 lines (42 loc) · 910 Bytes
/
read_event.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
/*
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
*/
#define FILE_PATH "/dev/input/event0"
int main()
{
struct input_event event[8];
int fd;
printf("Reading %s\n", FILE_PATH);
fd = open(FILE_PATH, O_RDWR);
if(fd < 0)
{
printf("ERROR: %s can not open\n", FILE_PATH);
exit(0);
}
read(fd, &event, sizeof(struct input_event)*2);
printf("value=%d\n", event[0].value);
/**
* Input event codes:
* http://www.kernel.org/doc/Documentation/input/event-codes.txt
*
*/
switch (event[0].code) { // type is EV_ABS
case ABS_X:
printf("X: %d\n", event[0].value);
break;
case ABS_Y:
printf("Y: %d\n", event[0].value);
break;
}
close(fd);
return 0;
}