diff --git a/sormc.h b/sormc.h index 053bf65..4fe1e00 100644 --- a/sormc.h +++ b/sormc.h @@ -9049,5 +9049,3 @@ void sormfmtd(char *csv) { } #endif - - diff --git a/tikker.c b/tikker.c index 4955c7f..c658ac2 100644 --- a/tikker.c +++ b/tikker.c @@ -1,19 +1,18 @@ +#include "sormc.h" +#include +#include #include #include #include -#include -#include -#include #include -#include "sormc.h" +#include #define MAX_DEVICES 32 #define DEVICE_PATH "/dev/input/event" - int is_keyboard(int fd) { char device_name[256] = {0}; - + if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) < 0) { return 0; } @@ -29,20 +28,20 @@ int main() { ulonglong times_pressed = 0; ulonglong times_released = 0; - sormq(db,"CREATE TABLE IF NOT EXISTS kevent (id INTEGER PRIMARY KEY AUTOINCREMENT, code,event,name,timestamp)"); - + sormq(db, "CREATE TABLE IF NOT EXISTS kevent (id INTEGER PRIMARY KEY AUTOINCREMENT, code,event,name,timestamp)"); + int keyboard_fds[MAX_DEVICES]; int num_keyboards = 0; - + for (int i = 0; i < MAX_DEVICES; i++) { char device_path[32]; snprintf(device_path, sizeof(device_path), "%s%d", DEVICE_PATH, i); - + int fd = open(device_path, O_RDONLY); if (fd < 0) { continue; } - + if (is_keyboard(fd)) { keyboard_fds[num_keyboards++] = fd; printf("Found keyboard: %s\n", device_path); @@ -60,11 +59,11 @@ int main() { struct input_event ev; fd_set read_fds; - + while (1) { FD_ZERO(&read_fds); int max_fd = -1; - + for (int i = 0; i < num_keyboards; i++) { FD_SET(keyboard_fds[i], &read_fds); if (keyboard_fds[i] > max_fd) { @@ -80,35 +79,30 @@ int main() { for (int i = 0; i < num_keyboards; i++) { if (FD_ISSET(keyboard_fds[i], &read_fds)) { ssize_t bytes = read(keyboard_fds[i], &ev, sizeof(struct input_event)); - + if (bytes == sizeof(struct input_event)) { if (ev.type == EV_KEY) { char key_name[256]; ioctl(keyboard_fds[i], EVIOCGNAME(sizeof(key_name)), key_name); - + printf("Keyboard: %s, ", key_name); - char * event_name = NULL; - if(ev.value == 1){ + char *event_name = NULL; + if (ev.value == 1) { event_name = "PRESSED"; times_pressed++; - }else if(ev.value == 0){ + } else if (ev.value == 0) { event_name = "RELEASED"; times_released++; - }else { + } else { event_name = "REPEATED"; times_repeated++; } - sormq(db, "INSERT INTO kevent (code, event, name,timestamp) VALUES (%d, %s, %s, DATETIME('now'))",ev.code,event_name,key_name); - printf("Event: %s, ", - ev.value == 1 ? "PRESSED" : - ev.value == 0 ? "RELEASED" : "REPEATED"); + sormq(db, "INSERT INTO kevent (code, event, name,timestamp) VALUES (%d, %s, %s, DATETIME('now'))", ev.code, + event_name, key_name); + printf("Event: %s, ", ev.value == 1 ? "PRESSED" : ev.value == 0 ? "RELEASED" : "REPEATED"); printf("Key Code: %d ", ev.code); - printf("Pr: %lld Rel: %lld Rep: %lld\n", - times_pressed, - times_released, - times_repeated - ); + printf("Pr: %lld Rel: %lld Rep: %lld\n", times_pressed, times_released, times_repeated); } } }