logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keylogger.c (1130B)


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