From cf0ed29561dae7898c0ad829b7d9e6415c7067fe Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 6 Nov 2013 13:08:04 -0500 Subject: [PATCH] refactor for less typing and hopefully a slight efficiency improvement --- ArduinoKeyboard.ino | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/ArduinoKeyboard.ino b/ArduinoKeyboard.ino index 5e899040..fddd15c6 100644 --- a/ArduinoKeyboard.ino +++ b/ArduinoKeyboard.ino @@ -139,32 +139,37 @@ void send_key_event() { for (int col = 0; col < COLS; col++) { int x = 0; int y = 0; - if (keymaps[current_keymap][row][col].flags & MOUSE_KEY ) { - if (keymaps[current_keymap][row][col].rawKey & MOUSE_UP) { + byte switchState = matrixState[row][col]; + Key mappedKey = keymaps[current_keymap][row][col]; + if (mappedKey.flags & MOUSE_KEY ) { + + + if (key_is_pressed(switchState)){ + if (mappedKey.rawKey & MOUSE_UP) { y--; } - if (keymaps[current_keymap][row][col].rawKey & MOUSE_DN) { + if (mappedKey.rawKey & MOUSE_DN) { y++; } - if (keymaps[current_keymap][row][col].rawKey & MOUSE_L) { + if (mappedKey.rawKey & MOUSE_L) { x--; } - if (keymaps[current_keymap][row][col].rawKey & MOUSE_R) { + if (mappedKey.rawKey & MOUSE_R) { x++; } Mouse.move(x, y, 0); + } + } else { - + if (key_toggled_on (switchState)){ + Keyboard.press(mappedKey.rawKey); } - - if (key_toggled_on (matrixState[row][col])) { - Keyboard.press(keymaps[current_keymap][row][col].rawKey); + else if (key_toggled_off (switchState)) { + Keyboard.release(mappedKey.rawKey); } - else if (key_toggled_off (matrixState[row][col])) { - Keyboard.release(keymaps[current_keymap][row][col].rawKey); } } }