diff options
| author | Ryan <fauxpark@gmail.com> | 2021-02-17 07:26:52 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-17 07:26:52 +1100 |
| commit | 3345ce268610edbca8f53bc2909c547485531603 (patch) | |
| tree | 9d984734f8aa5f2aa964e0151ab48eee936ef34b /tmk_core | |
| parent | cdb9d55956c67e1e2a9209522c1a2b30a7d9fb67 (diff) | |
| download | qmk_firmware-3345ce268610edbca8f53bc2909c547485531603.tar.gz qmk_firmware-3345ce268610edbca8f53bc2909c547485531603.zip | |
Add `tap_code_delay(code, delay)` (#11913)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/common/action.c | 21 | ||||
| -rw-r--r-- | tmk_core/common/action.h | 1 |
2 files changed, 14 insertions, 8 deletions
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 | */ |
| 947 | void tap_code(uint8_t code) { | 948 | void 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 | */ | ||
| 958 | void 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); | |||
| 100 | void register_code(uint8_t code); | 100 | void register_code(uint8_t code); |
| 101 | void unregister_code(uint8_t code); | 101 | void unregister_code(uint8_t code); |
| 102 | void tap_code(uint8_t code); | 102 | void tap_code(uint8_t code); |
| 103 | void tap_code_delay(uint8_t code, uint16_t delay); | ||
| 103 | void register_mods(uint8_t mods); | 104 | void register_mods(uint8_t mods); |
| 104 | void unregister_mods(uint8_t mods); | 105 | void unregister_mods(uint8_t mods); |
| 105 | void register_weak_mods(uint8_t mods); | 106 | void register_weak_mods(uint8_t mods); |
