You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* macros in json keymaps
* add advanced macro support to json
* add a note about escaping macro strings
* add simple examples
* format json
* add support for language specific keymap extras
* switch to dictionaries instead of inline text for macros
* use SS_TAP on the innermost tap keycode
* add the new macro format to the schema
* document the macro limit
* add the json keyword for syntax highlighting
* fix format that vscode screwed up
* Update feature_macros.md
* add tests for macros
* change ding to beep
* add json support for SENDSTRING_BELL
* update doc based on feedback from sigprof
* document host_layout
* remove unused var
* improve carriage return handling
* support tab characters as well
* Update docs/feature_macros.md
Co-authored-by: Nick Brassel <nick@tzarc.org>
* escape backslash characters
* format
* flake8
* Update quantum/quantum_keycodes.h
Co-authored-by: Nick Brassel <nick@tzarc.org>
Copy file name to clipboardexpand all lines: docs/feature_macros.md
+117-17
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,107 @@ Macros allow you to send multiple keystrokes when pressing just one key. QMK has
4
4
5
5
!> **Security Note**: While it is possible to use macros to send passwords, credit card numbers, and other sensitive information it is a supremely bad idea to do so. Anyone who gets a hold of your keyboard will be able to access that information by opening a text editor.
6
6
7
-
## `SEND_STRING()` & `process_record_user`
7
+
## Using Macros In JSON Keymaps
8
+
9
+
You can define up to 32 macros in a `keymap.json` file, as used by [Configurator](newbs_building_firmware_configurator.md), and `qmk compile`. You can define these macros in a list under the `macros` keyword, like this:
If you type in a language other than English, or use a non-QWERTY layout like Colemak, Dvorak, or Workman, you may have set your computer's input language to match this layout. This presents a challenge when creating macros- you may need to type different keys to get the same letters! To address this you can add the `host_language` key to your keymap.json, like so:
44
+
45
+
```json
46
+
{
47
+
"keyboard": "handwired/my_macropad",
48
+
"keymap": "my_keymap",
49
+
"host_layout": "dvorak",
50
+
"macros": [
51
+
["Hello, World!"]
52
+
],
53
+
"layout": "LAYOUT_all",
54
+
"layers": [
55
+
["MACRO_0"]
56
+
]
57
+
}
58
+
```
59
+
60
+
The current list of available languages is:
61
+
62
+
| belgian | bepo | br_abnt2 | canadian_multilingual |
Each macro is an array consisting of strings and objects (dictionaries.) Strings are typed to your computer while objects allow you to control how your macro is typed out.
79
+
80
+
#### Object Format
81
+
82
+
All objects have one required key: `action`. This tells QMK what the object does. There are currently 5 actions: beep, delay, down, tap, up
83
+
84
+
Only basic keycodes (prefixed by `KC_`) are supported. Do not include the `KC_` prefix when listing keycodes.
85
+
86
+
*`beep`
87
+
* Play a bell if the keyboard has [audio enabled](feature_audio.md).
88
+
* Example: `{"action": "beep"}`
89
+
*`delay`
90
+
* Pause macro playback. Duration is specified in milliseconds (ms).
91
+
* Example: `{"action": "delay", "duration": 500}`
92
+
*`down`
93
+
* Send a key down event for one or more keycodes.
94
+
* Example, single key: `{"action":"down", "keycodes": ["LSFT"]}`
95
+
* Example, multiple keys: `{"action":"down", "keycodes": ["CTRL", "LSFT"]}`
96
+
*`tap`
97
+
* Type a chord, which sends a down event for each key followed by an up event for each key.
98
+
* Example, single key: `{"action":"tap", "keycodes": ["F13"]}`
99
+
* Example, multiple keys: `{"action":"tap", "keycodes": ["CTRL", "LALT", "DEL"]}`
100
+
*`up`
101
+
* Send a key up event for one or more keycodes.
102
+
* Example, single key: `{"action":"up", "keycodes": ["LSFT"]}`
103
+
* Example, multiple keys: `{"action":"up", "keycodes": ["CTRL", "LSFT"]}`
104
+
105
+
## Using Macros in C Keymaps
106
+
107
+
### `SEND_STRING()` & `process_record_user`
8
108
9
109
Sometimes you want a key to type out words or phrases. For the most common situations, we've provided `SEND_STRING()`, which will type out a string (i.e. a sequence of characters) for you. All ASCII characters that are easily translatable to a keycode are supported (e.g. `qmk 123\n\t`).
In addition to the `process_record_user()` function, is the `post_process_record_user()` function. This runs after `process_record` and can be used to do things after a keystroke has been sent. This is useful if you want to have a key pressed before and released after a normal key, for instance.
You may want to use keys in your macros that you can't write down, such as `Ctrl` or `Home`.
137
237
You can send arbitrary keycodes by wrapping them in:
@@ -178,15 +278,15 @@ They can be used like this:
178
278
179
279
Which would send Left Control+`a` (Left Control down, `a`, Left Control up) - notice that they take strings (eg `"k"`), and not the `X_K` keycodes.
180
280
181
-
### Alternative Keymaps
281
+
#### Alternative Keymaps
182
282
183
283
By default, it assumes a US keymap with a QWERTY layout; if you want to change that (e.g. if your OS uses software Colemak), include this somewhere in your keymap:
184
284
185
285
```c
186
286
#include "sendstring_colemak.h"
187
287
```
188
288
189
-
### Strings in Memory
289
+
####Strings in Memory
190
290
191
291
If for some reason you're manipulating strings and need to print out something you just generated (instead of being a literal, constant string), you can use `send_string()`, like this:
There are some functions you may find useful in macro-writing. Keep in mind that while you can write some fairly advanced code within a macro, if your functionality gets too complex you may want to define a custom keycode instead. Macros are meant to be simple.
211
311
212
312
?> You can also use the functions described in [Useful function](ref_functions.md) and [Checking modifier state](feature_advanced_keycodes#checking-modifier-state) for additional functionality. For example, `reset_keyboard()` allows you to reset the keyboard as part of a macro and `get_mods() & MOD_MASK_SHIFT` lets you check for the existence of active shift modifiers.
213
313
214
-
### `record->event.pressed`
314
+
####`record->event.pressed`
215
315
216
316
This is a boolean value that can be tested to see if the switch is being pressed or released. An example of this is
217
317
@@ -223,47 +323,47 @@ This is a boolean value that can be tested to see if the switch is being pressed
223
323
}
224
324
```
225
325
226
-
### `register_code(<kc>);`
326
+
#### `register_code(<kc>);`
227
327
228
328
This sends the `<kc>` keydown event to the computer. Some examples would be `KC_ESC`, `KC_C`, `KC_4`, and even modifiers such as `KC_LSFT` and `KC_LGUI`.
229
329
230
-
### `unregister_code(<kc>);`
330
+
#### `unregister_code(<kc>);`
231
331
232
332
Parallel to `register_code` function, this sends the `<kc>` keyup event to the computer. If you don't use this, the key will be held down until it's sent.
233
333
234
-
### `tap_code(<kc>);`
334
+
#### `tap_code(<kc>);`
235
335
236
336
Sends `register_code(<kc>)` and then `unregister_code(<kc>)`. This is useful if you want to send both the press and release events ("tap" the key, rather than hold it).
237
337
238
338
If `TAP_CODE_DELAY` is defined (default 0), this function waits that many milliseconds before calling `unregister_code(<kc>)`. This can be useful when you are having issues with taps (un)registering.
239
339
240
340
If the keycode is `KC_CAPS`, it waits `TAP_HOLD_CAPS_DELAY` milliseconds instead (default 80), as macOS prevents accidental Caps Lock activation by waiting for the key to be held for a certain amount of time.
241
341
242
-
### `tap_code_delay(<kc>, <delay>);`
342
+
#### `tap_code_delay(<kc>, <delay>);`
243
343
244
344
Like `tap_code(<kc>)`, but with a `delay` parameter for specifying arbitrary intervals before sending the unregister event.
245
345
246
-
### `register_code16(<kc>);`, `unregister_code16(<kc>);` and `tap_code16(<kc>);`
346
+
#### `register_code16(<kc>);`, `unregister_code16(<kc>);` and `tap_code16(<kc>);`
247
347
248
348
These functions work similar to their regular counterparts, but allow you to use modded keycodes (with Shift, Alt, Control, and/or GUI applied to them).
249
349
250
350
Eg, you could use `register_code16(S(KC_5));` instead of registering the mod, then registering the keycode.
251
351
252
-
### `clear_keyboard();`
352
+
#### `clear_keyboard();`
253
353
254
354
This will clear all mods and keys currently pressed.
255
355
256
-
### `clear_mods();`
356
+
#### `clear_mods();`
257
357
258
358
This will clear all mods currently pressed.
259
359
260
-
### `clear_keyboard_but_mods();`
360
+
#### `clear_keyboard_but_mods();`
261
361
262
362
This will clear all keys besides the mods currently pressed.
263
363
264
-
## Advanced Example:
364
+
### Advanced Example:
265
365
266
-
### Super ALT↯TAB
366
+
#### Super ALT↯TAB
267
367
268
368
This 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.
0 commit comments