From 2ded3489143226bd70579369adafff3a649970a4 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 15 Jan 2014 21:34:53 -0500 Subject: [PATCH] first cut of mouse warping support --- ArduinoKeyboard.ino | 87 ++++++++++++++++++++++++++++++++++++++++++--- key_defs.h | 25 ++++++++++--- keymaps_generated.h | 6 ++++ layouts/numpad | 8 ++--- 4 files changed, 113 insertions(+), 13 deletions(-) diff --git a/ArduinoKeyboard.ino b/ArduinoKeyboard.ino index a30478cf..c0018680 100644 --- a/ArduinoKeyboard.ino +++ b/ArduinoKeyboard.ino @@ -273,9 +273,82 @@ void report(byte row, byte col, boolean value) // Mouse-related methods -// // +// + + + +int last_x; +int last_y; + + +int abs_left = -32767; +int abs_right = 32767; +int abs_bottom = -32767; +int abs_top = 32767; + +int section_top; +int section_bottom; +int section_left; +int section_right; +void begin_warping() { + section_left = abs_left; + section_right = abs_right; + section_top = abs_top; + section_bottom = abs_bottom; +} +boolean is_warping = false; +void warp_mouse(Key ninth) { + + // 1 2 3 + // 4 5 6 + // 7 8 9 + + if (is_warping == false) { + is_warping = true; + begin_warping(); + } + + + int next_width = (section_right - section_left) / 3; + int next_height = (section_bottom - section_top) / 3; + Keyboard.print("warping - the next width is "); + Keyboard.print(next_width); + Keyboard.print("warping - the next height is "); + Keyboard.print(next_height); + + if (ninth.rawKey * MOUSE_END_WARP) { + is_warping = false; + } + + if (ninth.rawKey & MOUSE_UP) { + Keyboard.print(" - up "); + section_bottom = section_top + next_height; + } else if (ninth.rawKey & MOUSE_DN) { + Keyboard.print(" - down "); + section_top = section_bottom - next_width; + } else { + Keyboard.print(" - vcenter "); + section_top = section_top + next_height; + section_bottom = section_bottom - next_height; + } + + if (ninth.rawKey & MOUSE_L) { + section_right = section_left + next_width; + Keyboard.print(" - left "); + + } else if (ninth.rawKey & MOUSE_R) { + section_left = section_right - next_width; + Keyboard.print(" - right "); + } else { + section_left = section_left + next_width; + section_right = section_right - next_width; + Keyboard.print(" - center horizontal "); + } + + Mouse.moveAbs(section_left + (section_right - section_left / 2), section_top + (section_bottom - section_top) / 2, 0); +} double mouse_accel (double cycles) { @@ -453,12 +526,18 @@ void send_key_events() for (byte col = 0; col < COLS; col++) { byte switchState = matrixState[row][col]; Key mappedKey = keymaps[active_keymap][row][col]; - if (mappedKey.flags & MOUSE_KEY ) { - handle_mouse_key_press(matrixState[row][col], keymaps[active_keymap][row][col], x, y); + if (mappedKey.flags & MOUSE_KEY ) { + if (mappedKey.rawKey & MOUSE_WARP) { + if (key_toggled_on(switchState)) { + warp_mouse(mappedKey); + } + } else { + handle_mouse_key_press(switchState, mappedKey, x, y); + } } else if (mappedKey.flags & SYNTHETIC_KEY) { - handle_synthetic_key_press(matrixState[row][col], keymaps[active_keymap][row][col]); + handle_synthetic_key_press(switchState, mappedKey); } else { if (key_is_pressed(switchState)) { diff --git a/key_defs.h b/key_defs.h index 6d5fe7d9..de9f63e3 100644 --- a/key_defs.h +++ b/key_defs.h @@ -14,11 +14,13 @@ #define IS_CONSUMER B00000100 -#define MOUSE_UP B0001 -#define MOUSE_DN B0010 -#define MOUSE_L B0100 -#define MOUSE_R B1000 - +#define MOUSE_UP B0000001 +#define MOUSE_DN B0000010 +#define MOUSE_L B0000100 +#define MOUSE_R B0001000 +#define MOUSE_CENTER B0010000 +#define MOUSE_WARP B0100000 +#define MOUSE_END_WARP B1000000 #define KEYMAP_0 0 #define KEYMAP_1 1 @@ -41,6 +43,19 @@ #define Key_macroKey1 (Key){ KEY_FLAGS|SYNTHETIC_KEY|IS_MACRO, 1} +#define Key_mouseWarp1 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_UP | MOUSE_L } +#define Key_mouseWarp2 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_UP } +#define Key_mouseWarp3 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_UP | MOUSE_R } +#define Key_mouseWarp4 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_L } +#define Key_mouseWarp5 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP } +#define Key_mouseWarp6 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP | MOUSE_R } +#define Key_mouseWarp7 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_DN | MOUSE_L } +#define Key_mouseWarp8 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_DN } +#define Key_mouseWarp9 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_DN | MOUSE_R } +#define Key_mouseWarp0 (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_WARP| MOUSE_END_WARP} + + + #define Key_mouseUpL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_L } #define Key_mouseUp (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP } #define Key_mouseUpR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_R } diff --git a/keymaps_generated.h b/keymaps_generated.h index 2161b9f9..bed13681 100644 --- a/keymaps_generated.h +++ b/keymaps_generated.h @@ -22,6 +22,12 @@ {Key_PageDn, Key_Comma, Key_Period, Key_J, Key_G, Key_Slash, Key_Esc, Key_Keymap2, Key_Semicolon, Key_W, Key_K, Key_Minus, Key_X, Key_LSquareBracket},\ {Key_LGUI, Key_E, Key_LShift, Key_Backspace, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\ }, +#define KEYMAP_NUMPAD { /* Generated keymap for NUMPAD */ {Key_skip, Key_skip, Key_skip, Key_skip, Key_skip, Key_skip, Key_skip, Key_skip, Key_skip, Key_7, Key_8, Key_9, Key_skip, Key_skip},\ + {Key_skip, Key_skip, Key_skip, Key_mouseWarp1, Key_mouseWarp2, Key_mouseWarp3, Key_skip, Key_skip, Key_skip, Key_4, Key_5, Key_6, Key_Minus, Key_skip},\ + {Key_PageUp, Key_skip, Key_skip, Key_mouseWarp4, Key_mouseWarp5, Key_mouseWarp6, Key_Tab, Key_Return, Key_skip, Key_1, Key_2, Key_3, Key_skip, Key_Equals},\ + {Key_PageDn, Key_skip, Key_skip, Key_mouseWarp7, Key_mouseWarp8, Key_mouseWarp9, Key_Esc, Key_Keymap1, Key_skip, Key_0, Key_Comma, Key_Period, Key_Enter, Key_skip},\ + {Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\ +}, #define KEYMAP_QWERTY { /* Generated keymap for QWERTY */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\ {Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_skip, Key_skip, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},\ {Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote},\ diff --git a/layouts/numpad b/layouts/numpad index 00bfd6b5..79f8ab72 100644 --- a/layouts/numpad +++ b/layouts/numpad @@ -1,6 +1,6 @@ #NAME: NUMPAD -skip skip skip skip skip skip skip skip skip 7 8 9 * skip -skip skip skip skip skip skip skip skip skip 4 5 6 - % -PageUp skip skip skip skip skip Tab Return skip 1 2 3 + = -PageDn skip skip skip skip skip Esc Keymap1 skip 0 , . ENTER skip +skip skip skip skip skip skip skip skip skip 7 8 9 skip skip +skip skip skip mouseWarp1 mouseWarp2 mouseWarp3 skip skip skip 4 5 6 - skip +PageUp skip skip mouseWarp4 mouseWarp5 mouseWarp6 Tab Return skip 1 2 3 skip = +PageDn skip skip mouseWarp7 mouseWarp8 mouseWarp9 Esc Keymap1 skip 0 , . Enter skip LGUI Backspace LShift LCtrl KeymapNext_Momentary skip skip skip skip KeymapNext_Momentary RCtrl RShift Space RAlt