From 2eb61391ee454eaf7e8b5002442681ce80bb13e0 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 24 Dec 2016 00:14:02 +0100 Subject: [PATCH] MouseKeys: Make 'em work! The mousekey handler was way too eager, and captured events that were not meant to be handled by it, like the `a` key. This has been fixed by removing the `KEY_MOUSE_CENTER` bit, and replacing it with `KEY_MOUSE_BUTTON`. That way, everything fits into the `IS_MOUSE_KEY` flag bit. While there, also fixed the id of the right mouse button. Signed-off-by: Gergely Nagy --- .../src/Keyboardio-MouseKeys.cpp | 22 ++++++++----------- .../Keyboardio-MouseKeys/src/MouseKeyDefs.h | 10 ++++----- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/libraries/Keyboardio-MouseKeys/src/Keyboardio-MouseKeys.cpp b/libraries/Keyboardio-MouseKeys/src/Keyboardio-MouseKeys.cpp index 8ce00d6a..cc03d5fe 100644 --- a/libraries/Keyboardio-MouseKeys/src/Keyboardio-MouseKeys.cpp +++ b/libraries/Keyboardio-MouseKeys/src/Keyboardio-MouseKeys.cpp @@ -23,22 +23,18 @@ static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) { } static bool handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState) { - if (! (mappedKey.flags & IS_INTERNAL) - && (mappedKey.rawKey == KEY_MOUSE_BTN_L - || mappedKey.rawKey == KEY_MOUSE_BTN_M - || mappedKey.rawKey == KEY_MOUSE_BTN_R)) { + if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY)) + return false; + + if (mappedKey.rawKey & KEY_MOUSE_BUTTON) { + uint8_t button = mappedKey.rawKey & ~KEY_MOUSE_BUTTON; + if (key_toggled_on(keyState)) { - MouseWrapper.press_button(mappedKey.rawKey); + MouseWrapper.press_button(button); } else if (key_toggled_off(keyState)) { - MouseWrapper.release_button(mappedKey.rawKey); + MouseWrapper.release_button(button); } - return true; - } - - if (!(mappedKey.flags & IS_MOUSE_KEY)) - return false; - - if (!(mappedKey.rawKey & KEY_MOUSE_WARP)) { + } else if (!(mappedKey.rawKey & KEY_MOUSE_WARP)) { handle_mouse_key_event(mappedKey, keyState); } else if (key_toggled_on(keyState)) { if (mappedKey.rawKey & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) { diff --git a/libraries/Keyboardio-MouseKeys/src/MouseKeyDefs.h b/libraries/Keyboardio-MouseKeys/src/MouseKeyDefs.h index e9c4b5dd..b8479b27 100644 --- a/libraries/Keyboardio-MouseKeys/src/MouseKeyDefs.h +++ b/libraries/Keyboardio-MouseKeys/src/MouseKeyDefs.h @@ -5,14 +5,14 @@ // Synthetic, not internal #define KEY_MOUSE_BTN_L 0x01 // Synthetic key #define KEY_MOUSE_BTN_M 0x02 // Synthetic key -#define KEY_MOUSE_BTN_R 0x04 // Synthetic key +#define KEY_MOUSE_BTN_R 0x03 // Synthetic key #define KEY_MOUSE_UP B0000001 #define KEY_MOUSE_DOWN B0000010 #define KEY_MOUSE_LEFT B0000100 #define KEY_MOUSE_RIGHT B0001000 -#define KEY_MOUSE_CENTER B0010000 +#define KEY_MOUSE_BUTTON B0010000 #define KEY_MOUSE_WARP B0100000 #define KEY_MOUSE_WARP_END B1000000 @@ -36,6 +36,6 @@ #define Key_mouseScrollDn #define Key_mouseScrollL #define Key_mouseScrollR -#define Key_mouseBtnL (Key){ KEY_FLAGS | SYNTHETIC, KEY_MOUSE_BTN_L } -#define Key_mouseBtnM (Key){ KEY_FLAGS | SYNTHETIC, KEY_MOUSE_BTN_M } -#define Key_mouseBtnR (Key){ KEY_FLAGS | SYNTHETIC, KEY_MOUSE_BTN_R } +#define Key_mouseBtnL (Key){ KEY_FLAGS | SYNTHETIC | IS_MOUSE_KEY, KEY_MOUSE_BUTTON | KEY_MOUSE_BTN_L } +#define Key_mouseBtnM (Key){ KEY_FLAGS | SYNTHETIC | IS_MOUSE_KEY, KEY_MOUSE_BUTTON | KEY_MOUSE_BTN_M } +#define Key_mouseBtnR (Key){ KEY_FLAGS | SYNTHETIC | IS_MOUSE_KEY, KEY_MOUSE_BUTTON | KEY_MOUSE_BTN_R }