aboutsummaryrefslogtreecommitdiff
path: root/keyboards/yosino58/lib/keylogger.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/yosino58/lib/keylogger.c')
-rw-r--r--keyboards/yosino58/lib/keylogger.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/keyboards/yosino58/lib/keylogger.c b/keyboards/yosino58/lib/keylogger.c
new file mode 100644
index 000000000..c50de94c2
--- /dev/null
+++ b/keyboards/yosino58/lib/keylogger.c
@@ -0,0 +1,45 @@
1#include <stdio.h>
2#include "yosino58.h"
3
4char keylog_str[24] = {};
5char keylogs_str[21] = {};
6int keylogs_str_idx = 0;
7
8const 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
16void 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
39const char *read_keylog(void) {
40 return keylog_str;
41}
42
43const char *read_keylogs(void) {
44 return keylogs_str;
45}