|
|
@ -20,100 +20,99 @@ uint32_t MouseKeys_::endTime;
|
|
|
|
uint32_t MouseKeys_::wheelEndTime;
|
|
|
|
uint32_t MouseKeys_::wheelEndTime;
|
|
|
|
|
|
|
|
|
|
|
|
void MouseKeys_::scrollWheel(uint8_t keyCode) {
|
|
|
|
void MouseKeys_::scrollWheel(uint8_t keyCode) {
|
|
|
|
if (millis() < wheelEndTime)
|
|
|
|
if (millis() < wheelEndTime)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
wheelEndTime = millis() + wheelDelay;
|
|
|
|
wheelEndTime = millis() + wheelDelay;
|
|
|
|
|
|
|
|
|
|
|
|
if (keyCode & KEY_MOUSE_UP)
|
|
|
|
if (keyCode & KEY_MOUSE_UP)
|
|
|
|
Mouse.move(0, 0, wheelSpeed);
|
|
|
|
Mouse.move(0, 0, wheelSpeed);
|
|
|
|
else if (keyCode & KEY_MOUSE_DOWN)
|
|
|
|
else if (keyCode & KEY_MOUSE_DOWN)
|
|
|
|
Mouse.move(0, 0, -wheelSpeed);
|
|
|
|
Mouse.move(0, 0, -wheelSpeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MouseKeys_::loopHook(bool postClear) {
|
|
|
|
void MouseKeys_::loopHook(bool postClear) {
|
|
|
|
if (postClear) {
|
|
|
|
if (postClear) {
|
|
|
|
mouseMoveIntent = 0;
|
|
|
|
mouseMoveIntent = 0;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mouseMoveIntent == 0) {
|
|
|
|
if (mouseMoveIntent == 0) {
|
|
|
|
MouseWrapper.accelStep = 0;
|
|
|
|
MouseWrapper.accelStep = 0;
|
|
|
|
endTime = 0;
|
|
|
|
endTime = 0;
|
|
|
|
accelEndTime = 0;
|
|
|
|
accelEndTime = 0;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (millis() < endTime)
|
|
|
|
if (millis() < endTime)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
endTime = millis() + speedDelay;
|
|
|
|
endTime = millis() + speedDelay;
|
|
|
|
|
|
|
|
|
|
|
|
int8_t moveX = 0, moveY = 0;
|
|
|
|
int8_t moveX = 0, moveY = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (millis() >= accelEndTime) {
|
|
|
|
if (millis() >= accelEndTime) {
|
|
|
|
if (MouseWrapper.accelStep < 255 - accelSpeed)
|
|
|
|
if (MouseWrapper.accelStep < 255 - accelSpeed)
|
|
|
|
MouseWrapper.accelStep += accelSpeed;
|
|
|
|
MouseWrapper.accelStep += accelSpeed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mouseMoveIntent & KEY_MOUSE_UP)
|
|
|
|
if (mouseMoveIntent & KEY_MOUSE_UP)
|
|
|
|
moveY = -speed;
|
|
|
|
moveY = -speed;
|
|
|
|
else if (mouseMoveIntent & KEY_MOUSE_DOWN)
|
|
|
|
else if (mouseMoveIntent & KEY_MOUSE_DOWN)
|
|
|
|
moveY = speed;
|
|
|
|
moveY = speed;
|
|
|
|
|
|
|
|
|
|
|
|
if (mouseMoveIntent & KEY_MOUSE_LEFT)
|
|
|
|
if (mouseMoveIntent & KEY_MOUSE_LEFT)
|
|
|
|
moveX = -speed;
|
|
|
|
moveX = -speed;
|
|
|
|
else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
|
|
|
|
else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
|
|
|
|
moveX = speed;
|
|
|
|
moveX = speed;
|
|
|
|
|
|
|
|
|
|
|
|
MouseWrapper.move(moveX, moveY);
|
|
|
|
MouseWrapper.move(moveX, moveY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
|
|
|
|
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
if (mappedKey.keyCode & KEY_MOUSE_BUTTON && !(mappedKey.keyCode & KEY_MOUSE_WARP)) {
|
|
|
|
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)) {
|
|
|
|
MouseWrapper.press_button(button);
|
|
|
|
MouseWrapper.press_button(button);
|
|
|
|
} else if (key_toggled_off(keyState)) {
|
|
|
|
} else if (key_toggled_off(keyState)) {
|
|
|
|
MouseWrapper.release_button(button);
|
|
|
|
MouseWrapper.release_button(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) {
|
|
|
|
} else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) {
|
|
|
|
if (key_toggled_on(keyState)) {
|
|
|
|
if (key_toggled_on(keyState)) {
|
|
|
|
endTime = millis() + speedDelay;
|
|
|
|
endTime = millis() + speedDelay;
|
|
|
|
accelEndTime = millis() + accelDelay;
|
|
|
|
accelEndTime = millis() + accelDelay;
|
|
|
|
wheelEndTime = 0;
|
|
|
|
wheelEndTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (key_is_pressed(keyState)) {
|
|
|
|
if (key_is_pressed(keyState)) {
|
|
|
|
if (mappedKey.keyCode & KEY_MOUSE_WHEEL) {
|
|
|
|
if (mappedKey.keyCode & KEY_MOUSE_WHEEL) {
|
|
|
|
scrollWheel (mappedKey.keyCode);
|
|
|
|
scrollWheel(mappedKey.keyCode);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
else
|
|
|
|
mouseMoveIntent |= mappedKey.keyCode;
|
|
|
|
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
|
|
|
|
// default, "no-op" conditionals
|
|
|
|
// default, "no-op" conditionals
|
|
|
|
MouseWrapper.warp(((mappedKey.keyCode & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) |
|
|
|
|
MouseWrapper.warp( ((mappedKey.keyCode & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) |
|
|
|
|
((mappedKey.keyCode & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) |
|
|
|
|
((mappedKey.keyCode & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) |
|
|
|
|
((mappedKey.keyCode & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00));
|
|
|
|
((mappedKey.keyCode & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MouseKeys_::MouseKeys_(void) {
|
|
|
|
MouseKeys_::MouseKeys_(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MouseKeys_::begin (void) {
|
|
|
|
MouseKeys_::begin(void) {
|
|
|
|
event_handler_hook_use(eventHandlerHook);
|
|
|
|
event_handler_hook_use(eventHandlerHook);
|
|
|
|
loop_hook_use(loopHook);
|
|
|
|
loop_hook_use(loopHook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MouseKeys_ MouseKeys;
|
|
|
|
MouseKeys_ MouseKeys;
|
|
|
|