aboutsummaryrefslogtreecommitdiffstats
path: root/docs/feature_macros.md
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2020-03-22 06:29:05 -0700
committerGitHub <noreply@github.com>2020-03-23 00:29:05 +1100
commit5117dff6a26aec4eca04fb9787b4f428884739bc (patch)
treeecc94acb888c3ed330c11008fa6324b1d73b12cc /docs/feature_macros.md
parente5d34fd084a7bdde0867749470b27c50e8144eb8 (diff)
downloadfirmware-5117dff6a26aec4eca04fb9787b4f428884739bc.tar.gz
firmware-5117dff6a26aec4eca04fb9787b4f428884739bc.tar.bz2
firmware-5117dff6a26aec4eca04fb9787b4f428884739bc.zip
Add Post Processing to process_record (#4892)
* Improve process_record system Code based on @colinta's * Rename and better handle functions * Fix incorrect function call to process_record_user * Add documentation for post_process_record * Add both get_event_keycode and get_record_keycode functions And add some comments about these functions * Update code format * Cleanup merge artifacts
Diffstat (limited to 'docs/feature_macros.md')
-rw-r--r--docs/feature_macros.md40
1 files changed, 40 insertions, 0 deletions
diff --git a/docs/feature_macros.md b/docs/feature_macros.md
index 99dd564bf..1bd2d74e7 100644
--- a/docs/feature_macros.md
+++ b/docs/feature_macros.md
@@ -88,6 +88,46 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
};
```
+### Advanced Macros
+
+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.
+
+In this example, we modify most normal keypresses so that `F22` is pressed before the keystroke is normally sent, and release it __only after__ it's been released.
+
+```c
+static uint8_t f22_tracker;
+
+bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ switch (keycode) {
+ case KC_A ... KC_F21: //notice how it skips over F22
+ case KC_F23 ... KC_EXSEL: //exsel is the last one before the modifier keys
+ if (record->event.pressed) {
+ register_code(KC_F22); //this means to send F22 down
+ f22_tracker++;
+ register_code(keycode);
+ return false;
+ }
+ break;
+ }
+ return true;
+}
+
+void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
+ switch (keycode) {
+ case KC_A ... KC_F21: //notice how it skips over F22
+ case KC_F23 ... KC_EXSEL: //exsel is the last one before the modifier keys
+ if (!record->event.pressed) {
+ f22_tracker--;
+ if (!f22_tracker) {
+ unregister_code(KC_F22); //this means to send F22 up
+ }
+ }
+ break;
+ }
+}
+```
+
+
### TAP, DOWN and UP
You may want to use keys in your macros that you can't write down, such as `Ctrl` or `Home`.