You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
5.0 KiB
141 lines
5.0 KiB
9 years ago
|
#include "key_events.h"
|
||
|
|
||
8 years ago
|
static const Key keymaps[KEYMAPS][ROWS][COLS] PROGMEM = { KEYMAP_LIST };
|
||
9 years ago
|
|
||
9 years ago
|
void handle_synthetic_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) {
|
||
9 years ago
|
if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) {
|
||
9 years ago
|
handle_mouse_key_event(mappedKey, currentState, previousState);
|
||
9 years ago
|
} else if (! (mappedKey.flags & IS_INTERNAL)
|
||
9 years ago
|
&& (mappedKey.rawKey == KEY_MOUSE_BTN_L
|
||
|
|| mappedKey.rawKey == KEY_MOUSE_BTN_M
|
||
|
|| mappedKey.rawKey == KEY_MOUSE_BTN_R)) {
|
||
9 years ago
|
if (key_toggled_on(currentState, previousState)) {
|
||
8 years ago
|
MouseWrapper.press_button(mappedKey.rawKey);
|
||
9 years ago
|
} else if (key_toggled_off(currentState, previousState)) {
|
||
8 years ago
|
MouseWrapper.release_button(mappedKey.rawKey);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
|
||
9 years ago
|
else if (key_toggled_on(currentState,previousState)) {
|
||
9 years ago
|
if (mappedKey.rawKey & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) {
|
||
9 years ago
|
// we don't pass in the left and up values because those are the
|
||
|
// default, "no-op" conditionals
|
||
9 years ago
|
MouseWrapper.warp( ((mappedKey.rawKey & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) |
|
||
|
((mappedKey.rawKey & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) |
|
||
|
((mappedKey.rawKey & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00) );
|
||
9 years ago
|
} else if (mappedKey.flags & IS_CONSUMER) {
|
||
|
ConsumerControl.press(mappedKey.rawKey);
|
||
|
} else if (mappedKey.flags & IS_INTERNAL) {
|
||
|
if (mappedKey.rawKey == LED_TOGGLE) {
|
||
|
LEDControl.next_mode();
|
||
|
}
|
||
|
} else if (mappedKey.flags & IS_SYSCTL) {
|
||
|
SystemControl.press(mappedKey.rawKey);
|
||
|
} else if (mappedKey.flags & IS_MACRO) {
|
||
|
if (mappedKey.rawKey == 1) {
|
||
|
Serial.print("Keyboard.IO keyboard driver v0.00");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
custom_handler_t eventHandlers[HOOK_MAX] = {
|
||
8 years ago
|
handle_key_event_default,
|
||
|
(custom_handler_t) NULL
|
||
8 years ago
|
};
|
||
8 years ago
|
|
||
8 years ago
|
Key lookup_key(byte keymap, byte row, byte col) {
|
||
|
Key mappedKey;
|
||
|
|
||
|
mappedKey.raw = pgm_read_word(&(keymaps[keymap][row][col]));
|
||
|
|
||
|
return mappedKey;
|
||
|
}
|
||
|
|
||
9 years ago
|
void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previousState) {
|
||
8 years ago
|
for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
|
||
8 years ago
|
custom_handler_t handler = eventHandlers[i];
|
||
|
if ((*handler)(row, col, currentState, previousState))
|
||
|
return;
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
bool handle_key_event_default(byte row, byte col, uint8_t currentState, uint8_t previousState) {
|
||
9 years ago
|
//for every newly pressed button, figure out what logical key it is and send a key down event
|
||
|
// for every newly released button, figure out what logical key it is and send a key up event
|
||
|
|
||
8 years ago
|
Key mappedKey = lookup_key(temporary_keymap, row, col);
|
||
|
Key baseKey = lookup_key(primary_keymap, row, col);
|
||
|
|
||
8 years ago
|
if (baseKey.flags & SWITCH_TO_KEYMAP) {
|
||
|
handle_keymap_key_event(baseKey, currentState, previousState);
|
||
9 years ago
|
} else if (mappedKey.flags & SYNTHETIC_KEY) {
|
||
9 years ago
|
handle_synthetic_key_event( mappedKey, currentState, previousState);
|
||
|
} else if (key_is_pressed(currentState, previousState)) {
|
||
9 years ago
|
press_key(mappedKey);
|
||
9 years ago
|
}
|
||
8 years ago
|
return true;
|
||
9 years ago
|
}
|
||
|
|
||
|
void press_key(Key mappedKey) {
|
||
|
if (mappedKey.flags & SHIFT_HELD) {
|
||
|
Keyboard.press(Key_LShift.rawKey);
|
||
|
}
|
||
|
if (mappedKey.flags & CTRL_HELD) {
|
||
|
Keyboard.press(Key_LCtrl.rawKey);
|
||
|
}
|
||
8 years ago
|
if (mappedKey.flags & LALT_HELD) {
|
||
|
Keyboard.press(Key_LAlt.rawKey);
|
||
|
}
|
||
|
if (mappedKey.flags & RALT_HELD) {
|
||
9 years ago
|
Keyboard.press(Key_RAlt.rawKey);
|
||
|
}
|
||
|
if (mappedKey.flags & GUI_HELD) {
|
||
|
Keyboard.press(Key_LGUI.rawKey);
|
||
|
}
|
||
|
Keyboard.press(mappedKey.rawKey);
|
||
|
}
|
||
|
|
||
|
|
||
9 years ago
|
void handle_keymap_key_event(Key keymapEntry, uint8_t currentState, uint8_t previousState) {
|
||
9 years ago
|
if (keymapEntry.flags & MOMENTARY ) {
|
||
9 years ago
|
if (key_toggled_on(currentState, previousState)) {
|
||
9 years ago
|
if ( keymapEntry.rawKey == KEYMAP_NEXT) {
|
||
|
temporary_keymap++;
|
||
|
} else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) {
|
||
|
temporary_keymap--;
|
||
|
} else {
|
||
|
temporary_keymap = keymapEntry.rawKey;
|
||
|
}
|
||
|
}
|
||
9 years ago
|
if (key_toggled_off(currentState, previousState)) {
|
||
9 years ago
|
temporary_keymap = primary_keymap;
|
||
|
}
|
||
|
|
||
|
// switch keymap and stay there
|
||
9 years ago
|
} else if (key_toggled_on(currentState, previousState)) {
|
||
9 years ago
|
temporary_keymap = primary_keymap = keymapEntry.rawKey;
|
||
|
Storage.save_primary_keymap(primary_keymap);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) {
|
||
|
if (key_is_pressed(currentState,previousState)) {
|
||
9 years ago
|
if (mappedKey.rawKey & KEY_MOUSE_UP) {
|
||
9 years ago
|
MouseWrapper.move(0,-1);
|
||
9 years ago
|
}
|
||
9 years ago
|
if (mappedKey.rawKey & KEY_MOUSE_DOWN) {
|
||
9 years ago
|
MouseWrapper.move(0,1);
|
||
9 years ago
|
}
|
||
9 years ago
|
if (mappedKey.rawKey & KEY_MOUSE_LEFT) {
|
||
9 years ago
|
MouseWrapper.move(-1,0);
|
||
9 years ago
|
}
|
||
9 years ago
|
if (mappedKey.rawKey & KEY_MOUSE_RIGHT) {
|
||
9 years ago
|
MouseWrapper.move(1,0);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|