]>
git.scottworley.com Git - keystroke-timestamps/blob - keystroke-timestamps.c
4 #include <linux/input.h>
9 #include <sys/select.h>
12 int main (int argc
, char **argv
)
15 char* device
= strdup("/dev/input/by-path/platform-i8042-serio-0-event-kbd");
16 struct option long_options
[] = {
17 {"device", required_argument
, 0, 'd' },
18 {"usec", no_argument
, &print_usec
, 1 },
22 int c
= getopt_long(argc
, argv
, "", long_options
, NULL
);
26 device
= strdup(optarg
);
29 if (c
!= 0) exit(EX_USAGE
);
32 int fd
= open(device
, O_RDONLY
);
34 err(EX_NOINPUT
, "Could not open keyboard event file");
38 fd_set all_inputs
, ready_inputs
;
40 FD_SET(fd
, &all_inputs
);
42 ready_inputs
= all_inputs
;
43 if (select(fd
+1, &ready_inputs
, NULL
, NULL
, NULL
) != 1) {
44 err(EX_IOERR
, "select");
46 int read_return
= read(fd
, &i
, sizeof(i
));
47 if (read_return
== -1) {
48 err(EX_IOERR
, "read");
50 if (read_return
!= sizeof(i
)) {
51 errx(EX_IOERR
, "Unexpected EOF");
53 if (i
.type
== 1 && i
.value
== 1) {
55 printf("%ld.%06ld\n", i
.time
.tv_sec
, i
.time
.tv_usec
);
57 printf("%ld\n", i
.time
.tv_sec
);