Implemented real time statistics.

This commit is contained in:
retoor 2024-12-08 19:33:01 +01:00
parent 13275a969b
commit f17d732df6
2 changed files with 13 additions and 2 deletions

BIN
tikker

Binary file not shown.

View File

@ -23,9 +23,12 @@ int is_keyboard(int fd) {
int main() { int main() {
db = sormc("tikker.db"); db = sormc("tikker.db");
ulonglong times_repeated = 0;
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 keyboard_fds[MAX_DEVICES];
@ -87,17 +90,25 @@ int main() {
char * event_name = NULL; char * event_name = NULL;
if(ev.value == 1){ if(ev.value == 1){
event_name = "PRESSED"; event_name = "PRESSED";
times_pressed++;
}else if(ev.value == 0){ }else if(ev.value == 0){
event_name = "RELEASED"; event_name = "RELEASED";
times_released++;
}else { }else {
event_name = "REPEATED"; 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); sormq(db, "INSERT INTO kevent (code, event, name,timestamp) VALUES (%d, %s, %s, DATETIME('now'))",ev.code,event_name,key_name);
printf("Event: %s, ", printf("Event: %s, ",
ev.value == 1 ? "PRESSED" : ev.value == 1 ? "PRESSED" :
ev.value == 0 ? "RELEASED" : "REPEATED"); ev.value == 0 ? "RELEASED" : "REPEATED");
printf("Key Code: %d\n", ev.code); printf("Key Code: %d ", ev.code);
printf("Pr: %lld Rel: %lld Rep: %lld\n",
times_pressed,
times_released,
times_repeated
);
} }
} }
} }