aboutsummaryrefslogtreecommitdiff
path: root/docs/feature_macros.md
diff options
context:
space:
mode:
authorroguepullrequest <roguepullrequest@users.noreply.github.com>2019-04-14 13:32:11 -0500
committerDrashna Jaelre <drashna@live.com>2019-04-14 11:32:11 -0700
commite7e13ebdd7dfa6b89326cc1b915539492153b648 (patch)
tree070d4a61f5eb8aef09ffa99f655f214b2db5090c /docs/feature_macros.md
parent02b74d521bf84ba776a5920289887ad418806311 (diff)
downloadqmk_firmware-e7e13ebdd7dfa6b89326cc1b915539492153b648.tar.gz
qmk_firmware-e7e13ebdd7dfa6b89326cc1b915539492153b648.zip
[Docs] Adding Alt↯Tab example macro (#5616)
Diffstat (limited to 'docs/feature_macros.md')
-rw-r--r--docs/feature_macros.md47
1 files changed, 46 insertions, 1 deletions
diff --git a/docs/feature_macros.md b/docs/feature_macros.md
index 743fc3ad5..fe45016e3 100644
--- a/docs/feature_macros.md
+++ b/docs/feature_macros.md
@@ -195,6 +195,49 @@ This will clear all mods currently pressed.
195 195
196This will clear all keys besides the mods currently pressed. 196This will clear all keys besides the mods currently pressed.
197 197
198## Advanced Example:
199
200### Super ALT↯TAB
201
202This macro will register `KC_LALT` and tap `KC_TAB`, then wait for 1000ms. If the key is tapped again, it will send another `KC_TAB`; if there is no tap, `KC_LALT` will be unregistered, thus allowing you to cycle through windows.
203
204```c
205bool is_alt_tab_active = false; # ADD this near the begining of keymap.c
206uint16_t alt_tab_timer = 0; # we will be using them soon.
207
208enum custom_keycodes { # Make sure have the awesome keycode ready
209 ALT_TAB = SAFE_RANGE,
210};
211
212bool process_record_user(uint16_t keycode, keyrecord_t *record) {
213 switch (keycode) { # This will do most of the grunt work with the keycodes.
214 case ALT_TAB:
215 if (record->event.pressed) {
216 if (!is_alt_tab_active) {
217 is_alt_tab_active = true;
218 register_code(KC_LALT);
219 }
220 alt_tab_timer = timer_read();
221 register_code(KC_TAB);
222 } else {
223 unregister_code(KC_TAB);
224 }
225 break;
226 }
227 return true;
228}
229
230void matrix_scan_user(void) { # The very important timer.
231 if (is_alt_tab_active) {
232 if (timer_elapsed(alt_tab_timer) > 1000) {
233 unregister_code16(LALT(KC_TAB));
234 is_alt_tab_active = false;
235 }
236 }
237}
238```
239
240---
198 241
199## **(DEPRECATED)** The Old Way: `MACRO()` & `action_get_macro` 242## **(DEPRECATED)** The Old Way: `MACRO()` & `action_get_macro`
200 243
@@ -273,7 +316,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
273``` 316```
274 317
275 318
276### Advanced Example: Single-Key Copy/Paste 319## Advanced Example:
320
321### Single-Key Copy/Paste
277 322
278This example defines a macro which sends `Ctrl-C` when pressed down, and `Ctrl-V` when released. 323This example defines a macro which sends `Ctrl-C` when pressed down, and `Ctrl-V` when released.
279 324