diff options
-rw-r--r-- | docs/feature_combo.md | 32 | ||||
-rw-r--r-- | quantum/process_keycode/process_combo.c | 43 | ||||
-rw-r--r-- | quantum/process_keycode/process_combo.h | 5 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 3 |
4 files changed, 73 insertions, 10 deletions
diff --git a/docs/feature_combo.md b/docs/feature_combo.md index 4cb1bcda0..9db7be511 100644 --- a/docs/feature_combo.md +++ b/docs/feature_combo.md | |||
@@ -59,19 +59,12 @@ void process_combo_event(uint8_t combo_index, bool pressed) { | |||
59 | switch(combo_index) { | 59 | switch(combo_index) { |
60 | case ZC_COPY: | 60 | case ZC_COPY: |
61 | if (pressed) { | 61 | if (pressed) { |
62 | register_code(KC_LCTL); | 62 | tap_code16(LCTL(KC_C)); |
63 | register_code(KC_C); | ||
64 | unregister_code(KC_C); | ||
65 | unregister_code(KC_LCTL); | ||
66 | } | 63 | } |
67 | break; | 64 | break; |
68 | |||
69 | case XV_PASTE: | 65 | case XV_PASTE: |
70 | if (pressed) { | 66 | if (pressed) { |
71 | register_code(KC_LCTL); | 67 | tap_code16(LCTL(KC_V)); |
72 | register_code(KC_V); | ||
73 | unregister_code(KC_V); | ||
74 | unregister_code(KC_LCTL); | ||
75 | } | 68 | } |
76 | break; | 69 | break; |
77 | } | 70 | } |
@@ -87,3 +80,24 @@ If you're using long combos, or even longer combos, you may run into issues with | |||
87 | In this case, you can add either `#define EXTRA_LONG_COMBOS` or `#define EXTRA_EXTRA_LONG_COMBOS` in your `config.h` file. | 80 | In this case, you can add either `#define EXTRA_LONG_COMBOS` or `#define EXTRA_EXTRA_LONG_COMBOS` in your `config.h` file. |
88 | 81 | ||
89 | You may also be able to enable action keys by defining `COMBO_ALLOW_ACTION_KEYS`. | 82 | You may also be able to enable action keys by defining `COMBO_ALLOW_ACTION_KEYS`. |
83 | |||
84 | ## Keycodes | ||
85 | |||
86 | You can enable, disable and toggle the Combo feature on the fly. This is useful if you need to disable them temporarily, such as for a game. | ||
87 | |||
88 | |Keycode |Description | | ||
89 | |----------|---------------------------------| | ||
90 | |`CMB_ON` |Turns on Combo feature | | ||
91 | |`CMB_OFF` |Turns off Combo feature | | ||
92 | |`CMB_TOG` |Toggles Combo feature on and off | | ||
93 | |||
94 | ## User callbacks | ||
95 | |||
96 | In addition to the keycodes, there are a few functions that you can use to set the status, or check it: | ||
97 | |||
98 | |Function |Description | | ||
99 | |-----------|--------------------------------------------------------------------| | ||
100 | | `combo_enable()` | Enables the combo feature | | ||
101 | | `combo_disable()` | Disables the combo feature, and clears the combo buffer | | ||
102 | | `combo_toggle()` | Toggles the state of the combo feature | | ||
103 | | `is_combo_enabled()` | Returns the status of the combo feature state (true or false) | | ||
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 2c6c9d0d5..d3c3b1673 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c | |||
@@ -28,6 +28,7 @@ static uint16_t timer = 0; | |||
28 | static uint8_t current_combo_index = 0; | 28 | static uint8_t current_combo_index = 0; |
29 | static bool drop_buffer = false; | 29 | static bool drop_buffer = false; |
30 | static bool is_active = false; | 30 | static bool is_active = false; |
31 | static bool b_combo_enable = true; // defaults to enabled | ||
31 | 32 | ||
32 | static uint8_t buffer_size = 0; | 33 | static uint8_t buffer_size = 0; |
33 | #ifdef COMBO_ALLOW_ACTION_KEYS | 34 | #ifdef COMBO_ALLOW_ACTION_KEYS |
@@ -128,6 +129,23 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { | |||
128 | drop_buffer = false; | 129 | drop_buffer = false; |
129 | bool no_combo_keys_pressed = true; | 130 | bool no_combo_keys_pressed = true; |
130 | 131 | ||
132 | if (keycode == CMB_ON && record->event.pressed) { | ||
133 | combo_enable(); | ||
134 | return true; | ||
135 | } | ||
136 | |||
137 | if (keycode == CMB_OFF && record->event.pressed) { | ||
138 | combo_disable(); | ||
139 | return true; | ||
140 | } | ||
141 | |||
142 | if (keycode == CMB_TOG && record->event.pressed) { | ||
143 | combo_toggle(); | ||
144 | return true; | ||
145 | } | ||
146 | |||
147 | if (!is_combo_enabled()) { return true; } | ||
148 | |||
131 | for (current_combo_index = 0; current_combo_index < COMBO_COUNT; | 149 | for (current_combo_index = 0; current_combo_index < COMBO_COUNT; |
132 | ++current_combo_index) { | 150 | ++current_combo_index) { |
133 | combo_t *combo = &key_combos[current_combo_index]; | 151 | combo_t *combo = &key_combos[current_combo_index]; |
@@ -166,7 +184,7 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { | |||
166 | } | 184 | } |
167 | 185 | ||
168 | void matrix_scan_combo(void) { | 186 | void matrix_scan_combo(void) { |
169 | if (is_active && timer && timer_elapsed(timer) > COMBO_TERM) { | 187 | if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { |
170 | 188 | ||
171 | /* This disables the combo, meaning key events for this | 189 | /* This disables the combo, meaning key events for this |
172 | * combo will be handled by the next processors in the chain | 190 | * combo will be handled by the next processors in the chain |
@@ -175,3 +193,26 @@ void matrix_scan_combo(void) { | |||
175 | dump_key_buffer(true); | 193 | dump_key_buffer(true); |
176 | } | 194 | } |
177 | } | 195 | } |
196 | |||
197 | void combo_enable(void) { | ||
198 | b_combo_enable = true; | ||
199 | } | ||
200 | |||
201 | void combo_disable(void) { | ||
202 | b_combo_enable = is_active = false; | ||
203 | timer = 0; | ||
204 | dump_key_buffer(true); | ||
205 | |||
206 | } | ||
207 | |||
208 | void combo_toggle(void) { | ||
209 | if (b_combo_enable) { | ||
210 | combo_disable(); | ||
211 | } else { | ||
212 | combo_enable(); | ||
213 | } | ||
214 | } | ||
215 | |||
216 | bool is_combo_enabled(void) { | ||
217 | return b_combo_enable; | ||
218 | } | ||
diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index f06d2d345..aab284957 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h | |||
@@ -58,4 +58,9 @@ bool process_combo(uint16_t keycode, keyrecord_t *record); | |||
58 | void matrix_scan_combo(void); | 58 | void matrix_scan_combo(void); |
59 | void process_combo_event(uint8_t combo_index, bool pressed); | 59 | void process_combo_event(uint8_t combo_index, bool pressed); |
60 | 60 | ||
61 | void combo_enable(void); | ||
62 | void combo_disable(void); | ||
63 | void combo_toggle(void); | ||
64 | bool is_combo_enabled(void); | ||
65 | |||
61 | #endif | 66 | #endif |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 779c355ef..207e0a826 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
@@ -489,6 +489,9 @@ enum quantum_keycodes { | |||
489 | // Right control, close paren | 489 | // Right control, close paren |
490 | KC_RAPC, | 490 | KC_RAPC, |
491 | 491 | ||
492 | CMB_ON, | ||
493 | CMB_OFF, | ||
494 | CMB_TOG, | ||
492 | // always leave at the end | 495 | // always leave at the end |
493 | SAFE_RANGE | 496 | SAFE_RANGE |
494 | }; | 497 | }; |