diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.h | 10 | ||||
| -rw-r--r-- | src/logger.h | 22 | ||||
| -rw-r--r-- | src/main.c | 45 |
3 files changed, 77 insertions, 0 deletions
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; +} |
