-
Notifications
You must be signed in to change notification settings - Fork 8
/
ev.c
46 lines (38 loc) · 929 Bytes
/
ev.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
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <asm/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <linux/input.h>
int main(void)
{
struct input_event ev[64];
ssize_t read_bytes;
unsigned int loop, yalv;
int fd;
puts("tu");
while (1) {
fd = open("/dev/input/event15", O_RDONLY);
if (fd >= 0)
break;
perror("open");
}
puts("tu1");
for (loop = 0; loop < 100; loop++) {
read_bytes = read(fd, ev, sizeof(struct input_event) * 64);
if (read_bytes < (ssize_t)sizeof(struct input_event)) {
perror("evtest: short read");
exit(1);
}
for (yalv = 0; yalv < (read_bytes / sizeof(struct input_event)); yalv++)
printf("Event: time %ld.%06ld, type %d, code %d, value %d\n",
ev[yalv].time.tv_sec, ev[yalv].time.tv_usec, ev[yalv].type,
ev[yalv].code, ev[yalv].value);
}
close(fd);
return 0;
}