From 6f2cd6be1d44fb13d75f66418c9a27b01b77a53d Mon Sep 17 00:00:00 2001 From: spv Date: Mon, 17 Nov 2025 16:47:32 -0500 Subject: add WIP report gen, systemd user service, work time tracker, sig handling --- src/key_tracker.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/key_tracker.c (limited to 'src/key_tracker.c') 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 +#include +#include + +#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); + } +} -- cgit v1.2.3