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