]>
git.scottworley.com Git - keystroke-timestamps/blob - keystroke-timestamps.c
6cb49731cba993b270561b790e55fed2f4f5657f
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 open_fd
= open(device
, O_RDONLY
);
34 err(EX_NOINPUT
, "Could not open keyboard event file");
39 fd_set all_inputs
, ready_inputs
;
41 FD_SET(open_fd
, &all_inputs
);
43 ready_inputs
= all_inputs
;
44 if (select(maxfd
+1, &ready_inputs
, NULL
, NULL
, NULL
) != 1) {
45 err(EX_IOERR
, "select");
47 for (int fd
=0; fd
<= maxfd
; fd
++) {
48 if (FD_ISSET(fd
, &ready_inputs
)) {
49 int read_return
= read(fd
, &i
, sizeof(i
));
50 if (read_return
== -1) {
51 err(EX_IOERR
, "read");
53 if (read_return
!= sizeof(i
)) {
54 errx(EX_IOERR
, "Unexpected EOF");
56 if (i
.type
== 1 && i
.value
== 1) {
58 printf("%ld.%06ld\n", i
.time
.tv_sec
, i
.time
.tv_usec
);
60 printf("%ld\n", i
.time
.tv_sec
);