From 72a1520a84a14ed5d3db8d9c0ab8cadcb6461233 Mon Sep 17 00:00:00 2001 From: Harley Mellifont Date: Fri, 27 Jan 2023 11:48:56 +1100 Subject: [PATCH] bugfix: sticky keys held for longer than `release-after-ms` get stuck Sticky keys work to modify the next keypress, but also have utility in being held to achieve certain behaviours such as making multiple selections with a mouse. The current implementation of sticky keys does not account for the case where a sticky key is held longer than `release-after-ms`. In this case, the sticky key gets stuck. This PR proposes releasing the sticky key 1ms after the key is released if `release-after-ms` has lapsed during the hold, so that the sticky key behaves like a momentary key for long holds. I have tested this for the past few days and have found it fixes my use cases. --- app/src/behaviors/behavior_sticky_key.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 267b81ab..cdc1038c 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -167,9 +167,8 @@ static int on_sticky_key_binding_released(struct zmk_behavior_binding *binding, sticky_key->release_at = event.timestamp + sticky_key->config->release_after_ms; // adjust timer in case this behavior was queued by a hold-tap int32_t ms_left = sticky_key->release_at - k_uptime_get(); - if (ms_left > 0) { - k_work_schedule(&sticky_key->release_timer, K_MSEC(ms_left)); - } + ms_left = ms_left > 0 ? ms_left : 1; + k_work_schedule(&sticky_key->release_timer, K_MSEC(ms_left)); return ZMK_BEHAVIOR_OPAQUE; }