From 34923f8f755409734f06c4c0ee516337146b144f Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 2 Feb 2017 23:17:34 +0100 Subject: [PATCH] Minor mouse movement optimalisation When acting on `moveIntent`, set up the direction first, and move the cursor only once, instead of twice (once for each axis). This makes the movement even smoother, and also saves us a few bytes of code. Signed-off-by: Gergely Nagy --- src/Keyboardio-MouseKeys.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Keyboardio-MouseKeys.cpp b/src/Keyboardio-MouseKeys.cpp index 4fb73917..23a85a64 100644 --- a/src/Keyboardio-MouseKeys.cpp +++ b/src/Keyboardio-MouseKeys.cpp @@ -17,18 +17,22 @@ void MouseKeys_::loopHook(bool postClear) { return; } + int8_t moveX = 0, moveY = 0; + if (MouseWrapper.mouseActiveForCycles < 255) MouseWrapper.mouseActiveForCycles++; if (mouseMoveIntent & KEY_MOUSE_UP) - MouseWrapper.move(0, -1); + moveY = -1; else if (mouseMoveIntent & KEY_MOUSE_DOWN) - MouseWrapper.move(0, 1); + moveY = 1; if (mouseMoveIntent & KEY_MOUSE_LEFT) - MouseWrapper.move(-1, 0); + moveX = -1; else if (mouseMoveIntent & KEY_MOUSE_RIGHT) - MouseWrapper.move(1, 0); + moveX = 1; + + MouseWrapper.move(moveX, moveY); } Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {