Implement mouse wheel support

With these changes, the vertical scrolling of the mouse wheel is now properly
supported. It has no acceleration, because the wheel doesn't have one either. It
has a delay, however, which I tried to tune to a reasonable speed.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent dbbc80190a
commit a3cca30e1f

@ -12,8 +12,24 @@ uint16_t MouseKeys_::speedDelay = 0;
uint8_t MouseKeys_::accelSpeed = 1;
uint16_t MouseKeys_::accelDelay = 50;
uint8_t MouseKeys_::wheelSpeed = 1;
uint16_t MouseKeys_::wheelDelay = 50;
uint32_t MouseKeys_::accelEndTime;
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) {
if (postClear) {
@ -69,9 +85,15 @@ Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyS
if (key_toggled_on(keyState)) {
endTime = millis() + speedDelay;
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)) {
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

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

@ -15,6 +15,7 @@
#define KEY_MOUSE_BUTTON B0010000
#define KEY_MOUSE_WARP B0100000
#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 }
@ -32,8 +33,8 @@
#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_mouseDnR (Key) { KEY_MOUSE_DOWN | KEY_MOUSE_RIGHT, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseScrollUp
#define Key_mouseScrollDn
#define Key_mouseScrollUp (Key) { KEY_MOUSE_WHEEL | KEY_MOUSE_UP, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseScrollDn (Key) { KEY_MOUSE_WHEEL | KEY_MOUSE_DOWN, KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY }
#define Key_mouseScrollL
#define Key_mouseScrollR
#define Key_mouseBtnL (Key) { KEY_MOUSE_BUTTON | KEY_MOUSE_BTN_L, KEY_FLAGS | SYNTHETIC | IS_MOUSE_KEY }

Loading…
Cancel
Save