implement `tap_code16_delay` (#17748)

master^2
JayceFayne 2022-07-23 20:21:20 +02:00 committed by GitHub
parent a6f3194397
commit d02cefe613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View File

@ -349,7 +349,7 @@ If the keycode is `KC_CAPS`, it waits `TAP_HOLD_CAPS_DELAY` milliseconds instead
Like `tap_code(<kc>)`, but with a `delay` parameter for specifying arbitrary intervals before sending the unregister event. Like `tap_code(<kc>)`, but with a `delay` parameter for specifying arbitrary intervals before sending the unregister event.
#### `register_code16(<kc>);`, `unregister_code16(<kc>);` and `tap_code16(<kc>);` #### `register_code16(<kc>);`, `unregister_code16(<kc>);`, `tap_code16(<kc>);` and `tap_code16_delay(<kc>, <delay>);`
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). 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).

View File

@ -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); register_code16(code);
if (code == KC_CAPS_LOCK) { for (uint16_t i = delay; i > 0; i--) {
wait_ms(TAP_HOLD_CAPS_DELAY); wait_ms(1);
} else if (TAP_CODE_DELAY > 0) {
wait_ms(TAP_CODE_DELAY);
} }
unregister_code16(code); 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) { __attribute__((weak)) bool process_action_kb(keyrecord_t *record) {
return true; return true;
} }

View File

@ -264,6 +264,7 @@ void shutdown_user(void);
void register_code16(uint16_t code); void register_code16(uint16_t code);
void unregister_code16(uint16_t code); void unregister_code16(uint16_t code);
void tap_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_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); const char *get_u8_str(uint8_t curr_num, char curr_pad);