diff options
| author | spv <spv@spv.sh> | 2025-11-17 12:37:33 -0500 |
|---|---|---|
| committer | spv <spv@spv.sh> | 2025-11-17 12:37:33 -0500 |
| commit | ea30c450e690513f32398388938b01ab7c8efe3e (patch) | |
| tree | a26c041efbd59d77ee031f66ee5691aaeb30e45f | |
technically functional...
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 15 | ||||
| -rw-r--r-- | README | 4 | ||||
| -rw-r--r-- | src/config.h | 10 | ||||
| -rw-r--r-- | src/logger.h | 22 | ||||
| -rw-r--r-- | src/main.c | 45 |
6 files changed, 97 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..23b98d2 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +CC=gcc + +all: bin bin/stroke_buddy + +clean: + rm -rf bin + +bin: + mkdir bin + +bin/stroke_buddy: src/main.c + ${CC} $^ -o $@ + +run: all + bin/stroke_buddy @@ -0,0 +1,4 @@ +stroke_buddy +============ + +linux keystroke tracker diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..d064cea --- /dev/null +++ b/src/config.h @@ -0,0 +1,10 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define KEYBOARD_EVDEV "/dev/input/event0" +#define PERKEY_LEN 0x100 + +#define LOG_LEVEL LOG_INSANEDEBUG +#define REPORT_PATH "/tmp/report%d.log" + +#endif diff --git a/src/logger.h b/src/logger.h new file mode 100644 index 0000000..4350cf1 --- /dev/null +++ b/src/logger.h @@ -0,0 +1,22 @@ +#ifndef LOGGER_H +#define LOGGER_H + +#include <stdio.h> + +enum log_levels { + LOG_ERROR, + LOG_INFO, + LOG_DEBUG, + LOG_INSANEDEBUG, +}; + +#define LOGFP stderr +#define LOGLEVEL + +#define LOG(LEVEL, args...) do { \ + if (LEVEL <= LOG_LEVEL) { \ + fprintf(LOGFP, args); \ + } \ +} while (0) + +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..3542f36 --- /dev/null +++ b/src/main.c @@ -0,0 +1,45 @@ +#include <linux/input.h> +#include <sys/time.h> +#include <stdio.h> + +#include "logger.h" +#include "config.h" + +int main(int argc, char* argv[]) { + FILE* evdev_fp = fopen(KEYBOARD_EVDEV, "r"); + FILE* report_fp = NULL; + + char* report_path = NULL; + + struct input_event pressed_key; + + int perkey_pressed[PERKEY_LEN + 1]; + int keys_pressed = 0; + + struct timeval start_time; + struct timeval press_time; + + gettimeofday(&start_time, NULL); + + asprintf(&report_path, REPORT_PATH, start_time.tv_sec); + + report_fp = fopen(report_path, "w"); + + do { + fread(&pressed_key, sizeof(pressed_key), 1, evdev_fp); + + gettimeofday(&press_time, NULL); + + if (pressed_key.value == 1) { + perkey_pressed[pressed_key.code < PERKEY_LEN ? pressed_key.code : PERKEY_LEN]; + keys_pressed++; + + LOG(LOG_DEBUG, "%d:", keys_pressed, pressed_key.type, pressed_key.code, pressed_key.value); + rewind(report_fp); + fprintf(report_fp, "%d\n", keys_pressed); + fflush(report_fp); + } + } while (1); + + return 0; +} |
