first cut of mouse warping support

pull/18/head
Jesse Vincent 11 years ago
parent c78384fd6b
commit 2ded348914

@ -277,6 +277,79 @@ void report(byte row, byte col, boolean value)
//
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)
{
double accel = atan((cycles / 50) - 5);
@ -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)) {

@ -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 }

@ -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},\

@ -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

Loading…
Cancel
Save