diff options
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); + } +} |
