keylogger.c (1130B)
1 #include <stdio.h> 2 3 char keylog_str[24] = {}; 4 char keylogs_str[21] = {}; 5 int keylogs_str_idx = 0; 6 7 const char code_to_name[60] = { 8 ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 9 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 10 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 11 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 12 'R', 'E', 'B', 'T', ' ', ' ', ' ', ' ', ' ', ' ', 13 ' ', ';', '\'', ' ', ',', '.', '/', ' ', ' ', ' '}; 14 15 void set_keylog(uint16_t keycode, keyrecord_t *record) { 16 char name = ' '; 17 if (keycode < 60) { 18 name = code_to_name[keycode]; 19 } 20 21 // update keylog 22 snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c", 23 record->event.key.row, record->event.key.col, 24 keycode, name); 25 26 // update keylogs 27 if (keylogs_str_idx == sizeof(keylogs_str) - 1) { 28 keylogs_str_idx = 0; 29 for (int i = 0; i < sizeof(keylogs_str) - 1; i++) { 30 keylogs_str[i] = ' '; 31 } 32 } 33 34 keylogs_str[keylogs_str_idx] = name; 35 keylogs_str_idx++; 36 } 37 38 const char *read_keylog(void) { 39 return keylog_str; 40 } 41 42 const char *read_keylogs(void) { 43 return keylogs_str; 44 }