1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
}
|