Merge pull request #3 from keyboardio/f/mousewheel

Add mousewheel support to the plugin
pull/365/head
Gergely Nagy 8 years ago committed by GitHub
commit fbe4c44179

@ -12,8 +12,24 @@ uint16_t MouseKeys_::speedDelay = 0;
uint8_t MouseKeys_::accelSpeed = 1; uint8_t MouseKeys_::accelSpeed = 1;
uint16_t MouseKeys_::accelDelay = 50; uint16_t MouseKeys_::accelDelay = 50;
uint8_t MouseKeys_::wheelSpeed = 1;
uint16_t MouseKeys_::wheelDelay = 50;
uint32_t MouseKeys_::accelEndTime; uint32_t MouseKeys_::accelEndTime;
uint32_t MouseKeys_::endTime; uint32_t MouseKeys_::endTime;
uint32_t MouseKeys_::wheelEndTime;
void MouseKeys_::scrollWheel(uint8_t keyCode) {
if (millis() < wheelEndTime)
return;
wheelEndTime = millis() + wheelDelay;
if (keyCode & KEY_MOUSE_UP)
Mouse.move(0, 0, wheelSpeed);
else if (keyCode & KEY_MOUSE_DOWN)
Mouse.move(0, 0, -wheelSpeed);
}
void MouseKeys_::loopHook(bool postClear) { void MouseKeys_::loopHook(bool postClear) {
if (postClear) { if (postClear) {
@ -57,7 +73,7 @@ Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyS
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY)) if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
return mappedKey; return mappedKey;
if (mappedKey.keyCode & KEY_MOUSE_BUTTON) { if (mappedKey.keyCode & KEY_MOUSE_BUTTON && !(mappedKey.keyCode & KEY_MOUSE_WARP)) {
uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON; uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON;
if (key_toggled_on(keyState)) { if (key_toggled_on(keyState)) {
@ -69,9 +85,15 @@ Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyS
if (key_toggled_on(keyState)) { if (key_toggled_on(keyState)) {
endTime = millis() + speedDelay; endTime = millis() + speedDelay;
accelEndTime = millis() + accelDelay; accelEndTime = millis() + accelDelay;
wheelEndTime = 0;
}
if (key_is_pressed(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_WHEEL) {
scrollWheel (mappedKey.keyCode);
}
else
mouseMoveIntent |= mappedKey.keyCode;
} }
if (key_is_pressed(keyState))
mouseMoveIntent |= mappedKey.keyCode;
} else if (key_toggled_on(keyState)) { } else if (key_toggled_on(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) { if (mappedKey.keyCode & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) {
// we don't pass in the left and up values because those are the // we don't pass in the left and up values because those are the

@ -13,12 +13,16 @@ class MouseKeys_ : public KaleidoscopePlugin {
static uint16_t speedDelay; static uint16_t speedDelay;
static uint8_t accelSpeed; static uint8_t accelSpeed;
static uint16_t accelDelay; static uint16_t accelDelay;
static uint8_t wheelSpeed;
static uint16_t wheelDelay;
private: private:
static uint8_t mouseMoveIntent; static uint8_t mouseMoveIntent;
static uint32_t endTime; static uint32_t endTime;
static uint32_t accelEndTime; static uint32_t accelEndTime;
static uint32_t wheelEndTime;
static void scrollWheel(uint8_t keyCode);
static void loopHook(bool postClear); static void loopHook(bool postClear);
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
}; };

@ -14,7 +14,8 @@
#define KEY_MOUSE_RIGHT B0001000 #define KEY_MOUSE_RIGHT B0001000
#define KEY_MOUSE_BUTTON B0010000 #define KEY_MOUSE_BUTTON B0010000
#define KEY_MOUSE_WARP B0100000 #define KEY_MOUSE_WARP B0100000
#define KEY_MOUSE_WARP_END B1000000 #define KEY_MOUSE_WARP_END B0010000
#define KEY_MOUSE_WHEEL B1000000
#define Key_mouseWarpNW (Key) { KEY_MOUSE_WARP| KEY_MOUSE_UP | KEY_MOUSE_LEFT, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY } #define Key_mouseWarpNW (Key) { KEY_MOUSE_WARP| KEY_MOUSE_UP | KEY_MOUSE_LEFT, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
@ -32,8 +33,8 @@
#define Key_mouseDnL (Key) { KEY_MOUSE_DOWN | KEY_MOUSE_LEFT, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY } #define Key_mouseDnL (Key) { KEY_MOUSE_DOWN | KEY_MOUSE_LEFT, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseDn (Key) { KEY_MOUSE_DOWN, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY } #define Key_mouseDn (Key) { KEY_MOUSE_DOWN, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseDnR (Key) { KEY_MOUSE_DOWN | KEY_MOUSE_RIGHT, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY } #define Key_mouseDnR (Key) { KEY_MOUSE_DOWN | KEY_MOUSE_RIGHT, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseScrollUp #define Key_mouseScrollUp (Key) { KEY_MOUSE_WHEEL | KEY_MOUSE_UP, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseScrollDn #define Key_mouseScrollDn (Key) { KEY_MOUSE_WHEEL | KEY_MOUSE_DOWN, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseScrollL #define Key_mouseScrollL
#define Key_mouseScrollR #define Key_mouseScrollR
#define Key_mouseBtnL (Key) { KEY_MOUSE_BUTTON | KEY_MOUSE_BTN_L, KEY_FLAGS | SYNTHETIC | IS_MOUSE_KEY } #define Key_mouseBtnL (Key) { KEY_MOUSE_BUTTON | KEY_MOUSE_BTN_L, KEY_FLAGS | SYNTHETIC | IS_MOUSE_KEY }

Loading…
Cancel
Save