// 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); } }