From ff4dfad1958e5b74d7a3e5f3fcdc7744ed76860e Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 13 Mar 2017 20:48:21 +0100 Subject: [PATCH] Support for holding Consumer/SystemControl keys Instead of calling the `.write` method of `ConsumerControl`/`SystemControl`, which registers the key, sends a report, then unregisters, and reports again, just `.press` it when the key is pressed, as we did before. However, since `.press` always sends a report, and so does `.releaseAll`, we can't have it the same way we do for `Keyboard`. We need to explicitly release the consumer/system key, when the triggering key is released too. Not doing so makes the key stuck, as we never release it, and that will upset the operating system very much. With this patch, we do an explicit release when the key toggles off, and thus, we support both holding the key, and allowing the OS to trigger repeat, and, the key won't be stuck, either! Fixes #120. Signed-off-by: Gergely Nagy --- src/key_events.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/key_events.cpp b/src/key_events.cpp index 38a7cc0a..e08a5768 100644 --- a/src/key_events.cpp +++ b/src/key_events.cpp @@ -7,15 +7,18 @@ static bool handle_synthetic_key_event(Key mappedKey, uint8_t keyState) { if (!(mappedKey.flags & SYNTHETIC)) return false; - if (!key_toggled_on(keyState)) - return true; - if (mappedKey.flags & IS_INTERNAL) { return false; } else if (mappedKey.flags & IS_CONSUMER) { - ConsumerControl.write(mappedKey.keyCode); + if (key_is_pressed(keyState)) + ConsumerControl.press(mappedKey.keyCode); + else if (key_was_pressed(keyState)) + ConsumerControl.release(mappedKey.keyCode); } else if (mappedKey.flags & IS_SYSCTL) { - SystemControl.write(mappedKey.keyCode); + if (key_is_pressed(keyState)) + SystemControl.press(mappedKey.keyCode); + else if (key_was_pressed(keyState)) + SystemControl.release(); } else if (mappedKey.flags & SWITCH_TO_KEYMAP) { // Should not happen, handled elsewhere. }