Always call the default handler

Instead of registering the default handler late, always call it at the end if no
other handler took care of the event. This makes it less of an issue to order
`Keyboardio.use()` and `Keyboardio.setup()`.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/68/head
Gergely Nagy 8 years ago
parent 1acc23063e
commit adf67f7d60

@ -15,8 +15,6 @@ Keyboardio_::setup(const byte keymap_count) {
LEDControl.setup();
temporary_keymap = primary_keymap = Storage.load_primary_keymap(keymap_count);
event_handler_hook_add (handle_key_event_default);
}
custom_loop_t loopHooks[HOOK_MAX];

@ -60,18 +60,7 @@ Key lookup_key(byte keymap, byte row, byte col) {
return mappedKey;
}
void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(keyState & INJECTED)) {
mappedKey = lookup_key(temporary_keymap, row, col);
}
for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
custom_handler_t handler = eventHandlers[i];
if ((*handler)(mappedKey, row, col, keyState))
return;
}
}
bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyState) {
static bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyState) {
//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
@ -131,3 +120,15 @@ void release_key(Key mappedKey) {
}
Keyboard.release(mappedKey.rawKey);
}
void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(keyState & INJECTED)) {
mappedKey = lookup_key(temporary_keymap, row, col);
}
for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
custom_handler_t handler = eventHandlers[i];
if ((*handler)(mappedKey, row, col, keyState))
return;
}
handle_key_event_default(mappedKey, row, col, keyState);
}

@ -48,6 +48,5 @@ void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState);
// Internal use
void press_key(Key mappedKey);
void release_key(Key mappedKey);
bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyState);
Key lookup_key(byte keymap, byte row, byte col);

Loading…
Cancel
Save