diff options
author | JayceFayne <13365789+JayceFayne@users.noreply.github.com> | 2022-07-23 20:21:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-23 19:21:20 +0100 |
commit | d02cefe613f5ba252c6917c7b0fc6b5b87993062 (patch) | |
tree | abbeeec40aacf3e52845702abb7cb31ce83bd1aa /quantum | |
parent | a6f3194397a515ade82f10b5547e82e2863c8685 (diff) | |
download | qmk_firmware-d02cefe613f5ba252c6917c7b0fc6b5b87993062.tar.gz qmk_firmware-d02cefe613f5ba252c6917c7b0fc6b5b87993062.zip |
implement `tap_code16_delay` (#17748)
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/quantum.c | 21 | ||||
-rw-r--r-- | quantum/quantum.h | 1 |
2 files changed, 17 insertions, 5 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index 0d5f398585..80fa1a3ced 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -93,16 +93,27 @@ __attribute__((weak)) void unregister_code16(uint16_t code) { } } -__attribute__((weak)) void tap_code16(uint16_t code) { +/** \brief Tap a keycode with a delay. + * + * \param code The modded keycode to tap. + * \param delay The amount of time in milliseconds to leave the keycode registered, before unregistering it. + */ +__attribute__((weak)) void tap_code16_delay(uint16_t code, uint16_t delay) { register_code16(code); - if (code == KC_CAPS_LOCK) { - wait_ms(TAP_HOLD_CAPS_DELAY); - } else if (TAP_CODE_DELAY > 0) { - wait_ms(TAP_CODE_DELAY); + for (uint16_t i = delay; i > 0; i--) { + wait_ms(1); } unregister_code16(code); } +/** \brief Tap a keycode with the default delay. + * + * \param code The modded keycode to tap. If `code` is `KC_CAPS_LOCK`, the delay will be `TAP_HOLD_CAPS_DELAY`, otherwise `TAP_CODE_DELAY`, if defined. + */ +__attribute__((weak)) void tap_code16(uint16_t code) { + tap_code16_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY); +} + __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } diff --git a/quantum/quantum.h b/quantum/quantum.h index f3a8a323c7..8d74f2be38 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -264,6 +264,7 @@ void shutdown_user(void); void register_code16(uint16_t code); void unregister_code16(uint16_t code); void tap_code16(uint16_t code); +void tap_code16_delay(uint16_t code, uint16_t delay); const char *get_numeric_str(char *buf, size_t buf_len, uint32_t curr_num, char curr_pad); const char *get_u8_str(uint8_t curr_num, char curr_pad); |