diff options
Diffstat (limited to 'quantum/process_keycode/process_chording.c')
-rw-r--r-- | quantum/process_keycode/process_chording.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_chording.c b/quantum/process_keycode/process_chording.c new file mode 100644 index 000000000..d7814629f --- /dev/null +++ b/quantum/process_keycode/process_chording.c | |||
@@ -0,0 +1,60 @@ | |||
1 | #include "process_chording.h" | ||
2 | |||
3 | bool keys_chord(uint8_t keys[]) { | ||
4 | uint8_t keys_size = sizeof(keys)/sizeof(keys[0]); | ||
5 | bool pass = true; | ||
6 | uint8_t in = 0; | ||
7 | for (uint8_t i = 0; i < chord_key_count; i++) { | ||
8 | bool found = false; | ||
9 | for (uint8_t j = 0; j < keys_size; j++) { | ||
10 | if (chord_keys[i] == (keys[j] & 0xFF)) { | ||
11 | in++; // detects key in chord | ||
12 | found = true; | ||
13 | break; | ||
14 | } | ||
15 | } | ||
16 | if (found) | ||
17 | continue; | ||
18 | if (chord_keys[i] != 0) { | ||
19 | pass = false; // makes sure rest are blank | ||
20 | } | ||
21 | } | ||
22 | return (pass && (in == keys_size)); | ||
23 | } | ||
24 | |||
25 | bool process_chording(uint16_t keycode, keyrecord_t *record) { | ||
26 | if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) { | ||
27 | if (record->event.pressed) { | ||
28 | if (!chording) { | ||
29 | chording = true; | ||
30 | for (uint8_t i = 0; i < CHORDING_MAX; i++) | ||
31 | chord_keys[i] = 0; | ||
32 | chord_key_count = 0; | ||
33 | chord_key_down = 0; | ||
34 | } | ||
35 | chord_keys[chord_key_count] = (keycode & 0xFF); | ||
36 | chord_key_count++; | ||
37 | chord_key_down++; | ||
38 | return false; | ||
39 | } else { | ||
40 | if (chording) { | ||
41 | chord_key_down--; | ||
42 | if (chord_key_down == 0) { | ||
43 | chording = false; | ||
44 | // Chord Dictionary | ||
45 | if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) { | ||
46 | register_code(KC_A); | ||
47 | unregister_code(KC_A); | ||
48 | return false; | ||
49 | } | ||
50 | for (uint8_t i = 0; i < chord_key_count; i++) { | ||
51 | register_code(chord_keys[i]); | ||
52 | unregister_code(chord_keys[i]); | ||
53 | return false; | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | return true; | ||
60 | } \ No newline at end of file | ||