diff options
| author | spv <spv@spv.sh> | 2025-11-17 16:47:32 -0500 |
|---|---|---|
| committer | spv <spv@spv.sh> | 2025-11-17 16:47:32 -0500 |
| commit | 6f2cd6be1d44fb13d75f66418c9a27b01b77a53d (patch) | |
| tree | 7ba44fa400145e77ef487b9fd1de36d692e7cd9f /src/key_tracker.c | |
| parent | 6f010046f0f17a5684a0f30423e2b3c6a41099d1 (diff) | |
add WIP report gen, systemd user service, work time tracker, sig handling
Diffstat (limited to 'src/key_tracker.c')
| -rw-r--r-- | src/key_tracker.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/key_tracker.c b/src/key_tracker.c new file mode 100644 index 0000000..205e29a --- /dev/null +++ b/src/key_tracker.c @@ -0,0 +1,41 @@ +// key tracker + +#include <linux/input.h> +#include <sys/time.h> +#include <stdlib.h> + +#include "report.h" +#include "common.h" + +keypresses_t keypresses; + +extern FILE* report_fp; + +void log_key(int key) { + struct timeval press_time; + keypress_t keypress; + + gettimeofday(&press_time, NULL); + + keypress.when = press_time.tv_sec + (press_time.tv_usec / 1000000.0); + keypress.what = key; + + if (keypresses.keys == NULL) { + keypresses.keys = calloc(KEYPRESSES_START_SIZE, sizeof(keypress_t)); + keypresses.length = 0; + keypresses.size = KEYPRESSES_START_SIZE; + } + + if (keypresses.length >= keypresses.size) { + keypresses.keys = reallocarray(keypresses.keys, keypresses.size + KEYPRESSES_ADDITIONAL_SIZE, sizeof(keypress_t)); + keypresses.size += KEYPRESSES_ADDITIONAL_SIZE; + + gen_report(report_fp); + } + + keypresses.keys[keypresses.length++] = keypress; + + if (key == KEY_ENTER) { + gen_report(report_fp); + } +} |
