feature(sticky_keys): add quick-release
when quick-release is enabled, the sticky key is released immediately after another key is pressed
This commit is contained in:
parent
a89d8a6ea4
commit
c925cf02dd
9 changed files with 76 additions and 8 deletions
|
@ -19,6 +19,7 @@
|
|||
#binding-cells = <1>;
|
||||
release-after-ms = <1000>;
|
||||
bindings = <&mo>;
|
||||
quick-release;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -13,3 +13,5 @@ properties:
|
|||
required: true
|
||||
release-after-ms:
|
||||
type: int
|
||||
quick-release:
|
||||
type: boolean
|
||||
|
|
|
@ -29,6 +29,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
|
||||
struct behavior_sticky_key_config {
|
||||
uint32_t release_after_ms;
|
||||
bool quick_release;
|
||||
struct zmk_behavior_binding behavior;
|
||||
};
|
||||
|
||||
|
@ -209,10 +210,12 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) {
|
|||
}
|
||||
if (sticky_key->timer_started) {
|
||||
stop_timer(sticky_key);
|
||||
if (sticky_key->config->quick_release) {
|
||||
release_sticky_key_behavior(sticky_key, ev->timestamp);
|
||||
}
|
||||
}
|
||||
sticky_key->modified_key_usage_page = ev->usage_page;
|
||||
sticky_key->modified_key_keycode = ev->keycode;
|
||||
|
||||
} else { // key up
|
||||
if (sticky_key->timer_started &&
|
||||
sticky_key->modified_key_usage_page == ev->usage_page &&
|
||||
|
@ -269,6 +272,7 @@ static struct behavior_sticky_key_data behavior_sticky_key_data;
|
|||
#define KP_INST(n) \
|
||||
static struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \
|
||||
.behavior = _TRANSFORM_ENTRY(0, n).release_after_ms = DT_INST_PROP(n, release_after_ms), \
|
||||
.quick_release = DT_INST_PROP(n, quick_release), \
|
||||
}; \
|
||||
DEVICE_AND_API_INIT(behavior_sticky_key_##n, DT_INST_LABEL(n), behavior_sticky_key_init, \
|
||||
&behavior_sticky_key_data, &behavior_sticky_key_config_##n, APPLICATION, \
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
s/.*hid_listener_keycode_//p
|
|
@ -0,0 +1,8 @@
|
|||
pressed: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
|
@ -0,0 +1,52 @@
|
|||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan-mock.h>
|
||||
|
||||
/*
|
||||
sticky layers should quick-release.
|
||||
Thus, the second keypress should be on the default layer, not on the lower_layer.
|
||||
*/
|
||||
|
||||
/ {
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&sk E &sl 1
|
||||
&kp A &kp B>;
|
||||
};
|
||||
|
||||
lower_layer {
|
||||
bindings = <
|
||||
&sk LEFT_CONTROL &kp X
|
||||
&kp Y &kp Z>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&kscan {
|
||||
events = <
|
||||
/* press sl 1 */
|
||||
ZMK_MOCK_PRESS(0,1,10)
|
||||
ZMK_MOCK_RELEASE(0,1,10)
|
||||
/* press X */
|
||||
ZMK_MOCK_PRESS(0,1,10)
|
||||
/* press A */
|
||||
ZMK_MOCK_PRESS(1,0,10)
|
||||
ZMK_MOCK_RELEASE(0,1,10)
|
||||
ZMK_MOCK_RELEASE(1,0,10)
|
||||
|
||||
/* repeat test to check if cleanup is done correctly */
|
||||
/* press sl 1 */
|
||||
ZMK_MOCK_PRESS(0,1,10)
|
||||
ZMK_MOCK_RELEASE(0,1,10)
|
||||
/* press X */
|
||||
ZMK_MOCK_PRESS(0,1,10)
|
||||
/* press Y */
|
||||
ZMK_MOCK_PRESS(1,0,10)
|
||||
ZMK_MOCK_RELEASE(0,1,10)
|
||||
ZMK_MOCK_RELEASE(1,0,10)
|
||||
>;
|
||||
};
|
|
@ -1,8 +1,8 @@
|
|||
pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00
|
||||
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00
|
||||
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
/* tap sk LEFT_CONTROL */
|
||||
ZMK_MOCK_PRESS(0,0,10)
|
||||
ZMK_MOCK_RELEASE(0,0,10)
|
||||
/* tap Y */
|
||||
/* tap A */
|
||||
ZMK_MOCK_PRESS(1,0,10)
|
||||
ZMK_MOCK_RELEASE(1,0,10)
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
|||
/* tap sk */
|
||||
ZMK_MOCK_PRESS(0,0,10)
|
||||
ZMK_MOCK_RELEASE(0,0,10)
|
||||
/* tap Y */
|
||||
/* tap A */
|
||||
ZMK_MOCK_PRESS(1,0,10)
|
||||
ZMK_MOCK_RELEASE(1,0,10)
|
||||
>;
|
||||
|
|
Loading…
Reference in a new issue