Add an explicit release event

Since macros and other injected keys do not clear the report, we need a way to
release keys. The new `release_key` function does just that, similar to how
`press_key` does it for key presses. It is called by the default event handler
when the `keyState` toggles off, and has the `INJECTED` bit set.

The reason behind this is that keys that will need this special treatment will
always be injected keys. And those injected keys that do not need this
treatment, can be handled by an event handler prior to the default.

This should fix the macros not releasing keys issue.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/58/head
Gergely Nagy 8 years ago
parent 22ebbc6b7a
commit 4aa6e14021

@ -52,6 +52,8 @@ bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyStat
handle_synthetic_key_event( mappedKey, keyState);
} else if (key_is_pressed(keyState)) {
press_key(mappedKey);
} else if (key_toggled_off(keyState) && (keyState & INJECTED)) {
release_key(mappedKey);
}
return true;
}
@ -76,6 +78,26 @@ void press_key(Key mappedKey) {
}
void release_key(Key mappedKey) {
if (mappedKey.flags & SHIFT_HELD) {
Keyboard.release(Key_LShift.rawKey);
}
if (mappedKey.flags & CTRL_HELD) {
Keyboard.release(Key_LCtrl.rawKey);
}
if (mappedKey.flags & LALT_HELD) {
Keyboard.release(Key_LAlt.rawKey);
}
if (mappedKey.flags & RALT_HELD) {
Keyboard.release(Key_RAlt.rawKey);
}
if (mappedKey.flags & GUI_HELD) {
Keyboard.release(Key_LGUI.rawKey);
}
Keyboard.release(mappedKey.rawKey);
}
void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.flags & SWITCH_TO_KEYMAP_MOMENTARY ) {
if (key_toggled_on(keyState)) {

@ -48,6 +48,7 @@ void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState);
// Internal use
void handle_synthetic_key_event( Key mappedKey, uint8_t keyState);
void press_key(Key mappedKey);
void release_key(Key mappedKey);
void handle_keymap_key_event(Key keymapEntry, uint8_t keyState);
bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyState);

Loading…
Cancel
Save