From ff92c670b0eb26102f303e74e1972896adb5392c Mon Sep 17 00:00:00 2001 From: Andrew Rae Date: Mon, 29 May 2023 22:48:38 -0400 Subject: [PATCH] feat(core): Adding pre-release for keys that were already pressed. This fixes #1207 and #1076 (and maybe more?). --- app/src/hid_listener.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/hid_listener.c b/app/src/hid_listener.c index 3a11101d54f6..8e020c7cdac5 100644 --- a/app/src/hid_listener.c +++ b/app/src/hid_listener.c @@ -19,6 +19,20 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); static int hid_listener_keycode_pressed(const struct zmk_keycode_state_changed *ev) { int err, explicit_mods_changed, implicit_mods_changed; + if (zmk_hid_is_pressed(ZMK_HID_USAGE(ev->usage_page, ev->keycode))) { + LOG_DBG("unregistering usage_page 0x%02X keycode 0x%02X since it was already pressed", + ev->usage_page, ev->keycode); + err = zmk_hid_release(ZMK_HID_USAGE(ev->usage_page, ev->keycode)); + if (err < 0) { + LOG_DBG("Unable to pre-release keycode"); + return err; + } + err = zmk_endpoints_send_report(ev->usage_page); + if (err < 0) { + LOG_ERR("Failed to send key report for pre-releasing keycode", err); + } + } + LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X", ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers); err = zmk_hid_press(ZMK_HID_USAGE(ev->usage_page, ev->keycode));