qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keylogger.c (1170B)


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