keylogger.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "crkbd.h"
  2. char keylog[40] = {};
  3. char keylogs[21] = {};
  4. int keylogs_idx = 0;
  5. 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. {
  14. char name = ' ';
  15. if (keycode < 60)
  16. {
  17. name = code_to_name[keycode];
  18. }
  19. // update keylog
  20. snprintf(keylog, sizeof(keylog), "%dx%d, k%2d : %c",
  21. record->event.key.row,
  22. record->event.key.col,
  23. keycode,
  24. name);
  25. // update keylogs
  26. if (keylogs_idx == sizeof(keylogs) - 1)
  27. {
  28. keylogs_idx = 0;
  29. for (int i = 0; i < sizeof(keylogs) - 1; i++)
  30. {
  31. keylogs[i] = ' ';
  32. }
  33. }
  34. keylogs[keylogs_idx] = name;
  35. keylogs_idx++;
  36. }
  37. char *read_keylog(void) {
  38. return keylog;
  39. }
  40. char *read_keylogs(void) {
  41. return keylogs;
  42. }