]> git.scottworley.com Git - keystroke-timestamps/blob - keystroke-timestamps.c
5322e6bff1b5682698a72d30c4f92012912c88d9
[keystroke-timestamps] / keystroke-timestamps.c
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <linux/input.h>
5 #include <err.h>
6 #include <sysexits.h>
7
8 int main ()
9 {
10 struct input_event i;
11 int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_RDONLY);
12 if (fd < 0) {
13 err(EX_NOINPUT, "Could not open keyboard event file");
14 }
15 while (read(fd, &i, sizeof(i)) == sizeof(i)) {
16 if (i.type == 1 && i.value == 1) {
17 printf("%ld.%ld\n", i.time.tv_sec, i.time.tv_usec);
18 fflush(stdout);
19 }
20 }
21 return 0;
22 }