From: Scott Worley Date: Thu, 26 Dec 2013 07:54:06 +0000 (-0800) Subject: Specify keyboard device as an option X-Git-Tag: v1.0.0~13 X-Git-Url: http://git.scottworley.com/keystroke-timestamps/commitdiff_plain/c02cb43bbdd8ae57b11cb1d6306ed8473af0a134?hp=--cc Specify keyboard device as an option --- c02cb43bbdd8ae57b11cb1d6306ed8473af0a134 diff --git a/keystroke-timestamps.c b/keystroke-timestamps.c index 2ab4c42..fd7de5d 100644 --- a/keystroke-timestamps.c +++ b/keystroke-timestamps.c @@ -11,20 +11,28 @@ int main (int argc, char **argv) { int print_usec = 0; + char* device = strdup("/dev/input/by-path/platform-i8042-serio-0-event-kbd"); struct option long_options[] = { + {"device", required_argument, 0, 'd' }, {"usec", no_argument, &print_usec, 1 }, {0, 0, 0, 0 }, }; while (1) { int c = getopt_long(argc, argv, "", long_options, NULL); if (c == -1) break; + if (c == 'd') { + free(device); + device = strdup(optarg); + continue; + } if (c != 0) exit(EX_USAGE); } - int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_RDONLY); + int fd = open(device, O_RDONLY); if (fd < 0) { err(EX_NOINPUT, "Could not open keyboard event file"); } + free(device); struct input_event i; while (read(fd, &i, sizeof(i)) == sizeof(i)) { if (i.type == 1 && i.value == 1) {