From 52b1fd5dd3f1cb260cd0fba28c4b5aa23dd3d0f0 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 29 Nov 2021 15:41:22 +0000 Subject: [PATCH] fix(behaviors): Capture mods for `&key_repeat` * When tracking the last keycode, also capture the currently held explicit modifiers to use when replaying the key later. --- app/src/behaviors/behavior_key_repeat.c | 2 ++ app/tests/key-repeat/behavior_keymap.dtsi | 2 +- .../events.patterns | 2 ++ .../keycode_events.snapshot | 12 ++++++++++++ .../native_posix.keymap | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/tests/key-repeat/press-and-release-with-explicit-modifiers/events.patterns create mode 100644 app/tests/key-repeat/press-and-release-with-explicit-modifiers/keycode_events.snapshot create mode 100644 app/tests/key-repeat/press-and-release-with-explicit-modifiers/native_posix.keymap diff --git a/app/src/behaviors/behavior_key_repeat.c b/app/src/behaviors/behavior_key_repeat.c index b2e28a6e..22de37d9 100644 --- a/app/src/behaviors/behavior_key_repeat.c +++ b/app/src/behaviors/behavior_key_repeat.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -93,6 +94,7 @@ static int key_repeat_keycode_state_changed_listener(const zmk_event_t *eh) { for (int u = 0; u < config->usage_pages_count; u++) { if (config->usage_pages[u] == ev->usage_page) { memcpy(&data->last_keycode_pressed, ev, sizeof(struct zmk_keycode_state_changed)); + data->last_keycode_pressed.implicit_modifiers |= zmk_hid_get_explicit_mods(); break; } } diff --git a/app/tests/key-repeat/behavior_keymap.dtsi b/app/tests/key-repeat/behavior_keymap.dtsi index 93b6d069..24902fc6 100644 --- a/app/tests/key-repeat/behavior_keymap.dtsi +++ b/app/tests/key-repeat/behavior_keymap.dtsi @@ -10,7 +10,7 @@ default_layer { bindings = < &key_repeat &kp A - &kp B &kp C_VOL_UP + &kp LCTRL &kp C_VOL_UP >; }; }; diff --git a/app/tests/key-repeat/press-and-release-with-explicit-modifiers/events.patterns b/app/tests/key-repeat/press-and-release-with-explicit-modifiers/events.patterns new file mode 100644 index 00000000..79471923 --- /dev/null +++ b/app/tests/key-repeat/press-and-release-with-explicit-modifiers/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode_//p +s/.*hid_implicit_modifiers_//p \ No newline at end of file diff --git a/app/tests/key-repeat/press-and-release-with-explicit-modifiers/keycode_events.snapshot b/app/tests/key-repeat/press-and-release-with-explicit-modifiers/keycode_events.snapshot new file mode 100644 index 00000000..628214a4 --- /dev/null +++ b/app/tests/key-repeat/press-and-release-with-explicit-modifiers/keycode_events.snapshot @@ -0,0 +1,12 @@ +pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x01 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x01 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x01 +released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x01 explicit_mods 0x00 +press: Modifiers set to 0x01 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x01 explicit_mods 0x00 +release: Modifiers set to 0x00 diff --git a/app/tests/key-repeat/press-and-release-with-explicit-modifiers/native_posix.keymap b/app/tests/key-repeat/press-and-release-with-explicit-modifiers/native_posix.keymap new file mode 100644 index 00000000..ab9622e4 --- /dev/null +++ b/app/tests/key-repeat/press-and-release-with-explicit-modifiers/native_posix.keymap @@ -0,0 +1,15 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = < + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_RELEASE(1,0,10) + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + >; +}; \ No newline at end of file