aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-02-17 07:26:52 +1100
committerGitHub <noreply@github.com>2021-02-17 07:26:52 +1100
commit3345ce268610edbca8f53bc2909c547485531603 (patch)
tree9d984734f8aa5f2aa964e0151ab48eee936ef34b
parentcdb9d55956c67e1e2a9209522c1a2b30a7d9fb67 (diff)
downloadqmk_firmware-3345ce268610edbca8f53bc2909c547485531603.tar.gz
qmk_firmware-3345ce268610edbca8f53bc2909c547485531603.zip
Add `tap_code_delay(code, delay)` (#11913)
Co-authored-by: Drashna Jaelre <drashna@live.com>
-rw-r--r--docs/feature_macros.md10
-rw-r--r--tmk_core/common/action.c21
-rw-r--r--tmk_core/common/action.h1
3 files changed, 22 insertions, 10 deletions
diff --git a/docs/feature_macros.md b/docs/feature_macros.md
index aa1ebc337..6e69ad642 100644
--- a/docs/feature_macros.md
+++ b/docs/feature_macros.md
@@ -233,9 +233,15 @@ Parallel to `register_code` function, this sends the `<kc>` keyup event to the c
233 233
234### `tap_code(<kc>);` 234### `tap_code(<kc>);`
235 235
236This 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). 236Sends `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 237
238If 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. 238If `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
240If 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
242### `tap_code_delay(<kc>, <delay>);`
243
244Like `tap_code(<kc>)`, but with a `delay` parameter for specifying arbitrary intervals before sending the unregister event.
239 245
240### `register_code16(<kc>);`, `unregister_code16(<kc>);` and `tap_code16(<kc>);` 246### `register_code16(<kc>);`, `unregister_code16(<kc>);` and `tap_code16(<kc>);`
241 247
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index e4a97e0bc..74bfc0626 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -940,20 +940,25 @@ void unregister_code(uint8_t code) {
940#endif 940#endif
941} 941}
942 942
943/** \brief Utilities for actions. (FIXME: Needs better description) 943/** \brief Tap a keycode with a delay.
944 * 944 *
945 * FIXME: Needs documentation. 945 * \param code The basic keycode to tap.
946 * \param delay The amount of time in milliseconds to leave the keycode registered, before unregistering it.
946 */ 947 */
947void tap_code(uint8_t code) { 948void tap_code_delay(uint8_t code, uint16_t delay) {
948 register_code(code); 949 register_code(code);
949 if (code == KC_CAPS) { 950 wait_ms(delay);
950 wait_ms(TAP_HOLD_CAPS_DELAY);
951 } else {
952 wait_ms(TAP_CODE_DELAY);
953 }
954 unregister_code(code); 951 unregister_code(code);
955} 952}
956 953
954/** \brief Tap a keycode with the default delay.
955 *
956 * \param code The basic keycode to tap. If `code` is `KC_CAPS`, the delay will be `TAP_HOLD_CAPS_DELAY`, otherwise `TAP_CODE_DELAY`, if defined.
957 */
958void tap_code(uint8_t code) {
959 tap_code_delay(code, code == KC_CAPS ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY);
960}
961
957/** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately. 962/** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately.
958 * 963 *
959 * \param mods A bitfield of modifiers to register. 964 * \param mods A bitfield of modifiers to register.
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index 81cd54369..9a991de1c 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -100,6 +100,7 @@ void process_action(keyrecord_t *record, action_t action);
100void register_code(uint8_t code); 100void register_code(uint8_t code);
101void unregister_code(uint8_t code); 101void unregister_code(uint8_t code);
102void tap_code(uint8_t code); 102void tap_code(uint8_t code);
103void tap_code_delay(uint8_t code, uint16_t delay);
103void register_mods(uint8_t mods); 104void register_mods(uint8_t mods);
104void unregister_mods(uint8_t mods); 105void unregister_mods(uint8_t mods);
105void register_weak_mods(uint8_t mods); 106void register_weak_mods(uint8_t mods);