From 4aa6e1402140ddec1a9c89d09e3b3ff8e9072829 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 28 Nov 2016 23:01:55 +0100 Subject: [PATCH] Add an explicit release event Since macros and other injected keys do not clear the report, we need a way to release keys. The new `release_key` function does just that, similar to how `press_key` does it for key presses. It is called by the default event handler when the `keyState` toggles off, and has the `INJECTED` bit set. The reason behind this is that keys that will need this special treatment will always be injected keys. And those injected keys that do not need this treatment, can be handled by an event handler prior to the default. This should fix the macros not releasing keys issue. Signed-off-by: Gergely Nagy --- src/key_events.cpp | 22 ++++++++++++++++++++++ src/key_events.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/key_events.cpp b/src/key_events.cpp index ff071c66..e2692f3d 100644 --- a/src/key_events.cpp +++ b/src/key_events.cpp @@ -52,6 +52,8 @@ bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyStat handle_synthetic_key_event( mappedKey, keyState); } else if (key_is_pressed(keyState)) { press_key(mappedKey); + } else if (key_toggled_off(keyState) && (keyState & INJECTED)) { + release_key(mappedKey); } return true; } @@ -76,6 +78,26 @@ void press_key(Key mappedKey) { } +void release_key(Key mappedKey) { + if (mappedKey.flags & SHIFT_HELD) { + Keyboard.release(Key_LShift.rawKey); + } + if (mappedKey.flags & CTRL_HELD) { + Keyboard.release(Key_LCtrl.rawKey); + } + if (mappedKey.flags & LALT_HELD) { + Keyboard.release(Key_LAlt.rawKey); + } + if (mappedKey.flags & RALT_HELD) { + Keyboard.release(Key_RAlt.rawKey); + } + if (mappedKey.flags & GUI_HELD) { + Keyboard.release(Key_LGUI.rawKey); + } + Keyboard.release(mappedKey.rawKey); +} + + void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) { if (keymapEntry.flags & SWITCH_TO_KEYMAP_MOMENTARY ) { if (key_toggled_on(keyState)) { diff --git a/src/key_events.h b/src/key_events.h index d7128a1b..2bc6d799 100644 --- a/src/key_events.h +++ b/src/key_events.h @@ -48,6 +48,7 @@ void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState); // Internal use void handle_synthetic_key_event( Key mappedKey, uint8_t keyState); void press_key(Key mappedKey); +void release_key(Key mappedKey); void handle_keymap_key_event(Key keymapEntry, uint8_t keyState); bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyState);