diff options
Diffstat (limited to 'docs/feature_macros.md')
-rw-r--r-- | docs/feature_macros.md | 97 |
1 files changed, 53 insertions, 44 deletions
diff --git a/docs/feature_macros.md b/docs/feature_macros.md index 79419abd2..743fc3ad5 100644 --- a/docs/feature_macros.md +++ b/docs/feature_macros.md | |||
@@ -146,9 +146,59 @@ send_string(my_str); | |||
146 | SEND_STRING(".."SS_TAP(X_END)); | 146 | SEND_STRING(".."SS_TAP(X_END)); |
147 | ``` | 147 | ``` |
148 | 148 | ||
149 | ## The Old Way: `MACRO()` & `action_get_macro` | ||
150 | 149 | ||
151 | ?> This is inherited from TMK, and hasn't been updated - it's recommend that you use `SEND_STRING` and `process_record_user` instead. | 150 | ## Advanced Macro Functions |
151 | |||
152 | 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. | ||
153 | |||
154 | ### `record->event.pressed` | ||
155 | |||
156 | This is a boolean value that can be tested to see if the switch is being pressed or released. An example of this is | ||
157 | |||
158 | ```c | ||
159 | if (record->event.pressed) { | ||
160 | // on keydown | ||
161 | } else { | ||
162 | // on keyup | ||
163 | } | ||
164 | ``` | ||
165 | |||
166 | ### `register_code(<kc>);` | ||
167 | |||
168 | 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`. | ||
169 | |||
170 | ### `unregister_code(<kc>);` | ||
171 | |||
172 | 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. | ||
173 | |||
174 | ### `tap_code(<kc>);` | ||
175 | |||
176 | This will send `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). | ||
177 | |||
178 | If you're having issues with taps (un)registering, you can add a delay between the register and unregister events by setting `#define TAP_CODE_DELAY 100` in your `config.h` file. The value is in milliseconds. | ||
179 | |||
180 | ### `register_code16(<kc>);`, `unregister_code16(<kc>);` and `tap_code16(<kc>);` | ||
181 | |||
182 | 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). | ||
183 | |||
184 | Eg, you could use `register_code16(S(KC_5));` instead of registering the mod, then registering the keycode. | ||
185 | |||
186 | ### `clear_keyboard();` | ||
187 | |||
188 | This will clear all mods and keys currently pressed. | ||
189 | |||
190 | ### `clear_mods();` | ||
191 | |||
192 | This will clear all mods currently pressed. | ||
193 | |||
194 | ### `clear_keyboard_but_mods();` | ||
195 | |||
196 | This will clear all keys besides the mods currently pressed. | ||
197 | |||
198 | |||
199 | ## **(DEPRECATED)** The Old Way: `MACRO()` & `action_get_macro` | ||
200 | |||
201 | !> This is inherited from TMK, and hasn't been updated - it's recommended that you use `SEND_STRING` and `process_record_user` instead. | ||
152 | 202 | ||
153 | By default QMK assumes you don't have any macros. To define your macros you create an `action_get_macro()` function. For example: | 203 | By default QMK assumes you don't have any macros. To define your macros you create an `action_get_macro()` function. For example: |
154 | 204 | ||
@@ -222,49 +272,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
222 | }; | 272 | }; |
223 | ``` | 273 | ``` |
224 | 274 | ||
225 | ## Advanced Macro Functions | ||
226 | |||
227 | 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. | ||
228 | |||
229 | ### `record->event.pressed` | ||
230 | |||
231 | This is a boolean value that can be tested to see if the switch is being pressed or released. An example of this is | ||
232 | |||
233 | ```c | ||
234 | if (record->event.pressed) { | ||
235 | // on keydown | ||
236 | } else { | ||
237 | // on keyup | ||
238 | } | ||
239 | ``` | ||
240 | |||
241 | ### `register_code(<kc>);` | ||
242 | |||
243 | 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`. | ||
244 | |||
245 | ### `unregister_code(<kc>);` | ||
246 | |||
247 | 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. | ||
248 | |||
249 | ### `tap_code(<kc>);` | ||
250 | |||
251 | This will send `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). | ||
252 | |||
253 | If you're having issues with taps (un)registering, you can add a delay between the register and unregister events by setting `#define TAP_CODE_DELAY 100` in your `config.h` file. The value is in milliseconds. | ||
254 | |||
255 | ### `clear_keyboard();` | ||
256 | |||
257 | This will clear all mods and keys currently pressed. | ||
258 | |||
259 | ### `clear_mods();` | ||
260 | |||
261 | This will clear all mods currently pressed. | ||
262 | |||
263 | ### `clear_keyboard_but_mods();` | ||
264 | |||
265 | This will clear all keys besides the mods currently pressed. | ||
266 | 275 | ||
267 | ## Advanced Example: Single-Key Copy/Paste | 276 | ### Advanced Example: Single-Key Copy/Paste |
268 | 277 | ||
269 | This example defines a macro which sends `Ctrl-C` when pressed down, and `Ctrl-V` when released. | 278 | This example defines a macro which sends `Ctrl-C` when pressed down, and `Ctrl-V` when released. |
270 | 279 | ||