Created
November 12, 2020 13:30
Mouse Handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mouseHandler(int key, int state, bool transition, int repetitions) { | |
if(transition && (key == 0 || key == 2)) { | |
char mouseButton = MOUSE_LEFT; | |
if(key == 2) mouseButton = MOUSE_RIGHT; | |
if(state == BTN_PRESSED) { | |
Mouse.press(mouseButton); | |
} else { | |
Mouse.release(mouseButton); | |
} | |
} else if(transition && state == BTN_PRESSED && (key == 3 || key == 4)){ | |
//the mouse wheel works better as key presses but we just have to capture the pressed | |
Mouse.move(0,0,key == 3 ? 1 : -1); | |
} else if (state == BTN_PRESSED && (key == 1 || key == 5 || key == 6 || key == 7)) { | |
signed char xval = 0, yval = 0; | |
int accel = (repetitions / 10)+1; | |
if(key == 1) yval = -accel; | |
else if(key == 5) xval = accel; | |
else if(key == 6) yval = accel; | |
else if(key == 7) xval = -accel; | |
Mouse.move(xval,yval,0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment