diff --git a/tikker b/tikker index 9c89e74..0ba69d2 100755 Binary files a/tikker and b/tikker differ diff --git a/tikker.c b/tikker.c index 3221e72..1a39463 100644 --- a/tikker.c +++ b/tikker.c @@ -7,6 +7,8 @@ #include #include +#define DATABASE_NAME "tikker.db" +#define DEVICE_TO_READ_DEFAULT "keyboard" #define MAX_DEVICES 32 #define DEVICE_PATH "/dev/input/event" @@ -50,19 +52,21 @@ const char *keycode_to_char[] = { -int is_keyboard(int fd) { - char device_name[256] = {0}; +char * resolve_device_name(int fd) { + static char device_name[256]; + device_name[0] = 0; if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) < 0) { return 0; } - - return strstr(device_name, "keyboard") != NULL; + return device_name; } -int main() { +int main(int argc, char *argv[]) { - int db = sormc("tikker.db"); + char * device_to_read = rargs_get_option_string(argc, argv, "--device", DEVICE_TO_READ_DEFAULT); + + int db = sormc(DATABASE_NAME); ulonglong times_repeated = 0; ulonglong times_pressed = 0; @@ -81,17 +85,26 @@ int main() { if (fd < 0) { continue; } + char * device_name = resolve_device_name(fd); + if(!device_name) + { + close(fd); + continue; + } + bool is_device_to_read = strstr(device_name, device_to_read) != NULL; + printf("[%s] %s. Mount: %s.\n", is_device_to_read ? "-" : "+", device_name, device_path); - if (is_keyboard(fd)) { + if (is_device_to_read) { keyboard_fds[num_keyboards++] = fd; - printf("Found keyboard: %s\n", device_path); } else { close(fd); } } if (num_keyboards == 0) { - fprintf(stderr, "No keyboard found.\n"); + fprintf(stderr, "No keyboard found. Do you execute under root?\n" + "If your device is listed above with a minus[-] in front of it,\n" + "execute this application using --device='[DEVICE_NAME]'\n"); return 1; }