Skip to content

Commit

Permalink
fix(behaviors): Capture mods for &key_repeat
Browse files Browse the repository at this point in the history
* When tracking the last keycode, also capture the currently held
  explicit modifiers to use when replaying the key later.
  • Loading branch information
petejohanson committed Jan 31, 2022
1 parent 70bb7c9 commit 52b1fd5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/behaviors/behavior_key_repeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <drivers/behavior.h>
#include <logging/log.h>
#include <zmk/behavior.h>
#include <zmk/hid.h>

#include <zmk/event_manager.h>
#include <zmk/events/keycode_state_changed.h>
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/tests/key-repeat/behavior_keymap.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
default_layer {
bindings = <
&key_repeat &kp A
&kp B &kp C_VOL_UP
&kp LCTRL &kp C_VOL_UP
>;
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s/.*hid_listener_keycode_//p
s/.*hid_implicit_modifiers_//p
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
#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)
>;
};

0 comments on commit 52b1fd5

Please sign in to comment.