Merge pull request #152 from keyboardio/f/key-masking

Implement key masking for momentary layer keys
pull/156/head
Jesse Vincent 7 years ago committed by GitHub
commit bb96bbb438

@ -47,6 +47,21 @@ void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(keyState & INJECTED)) {
mappedKey = Layer.lookup(row, col);
}
/* If the key we are dealing with is masked, ignore it until it is released.
* When releasing it, clear the mask, so future key events can be handled
* appropriately.
*
* See layers.cpp for an example that masks keys, and the reason why it does
* so.
*/
if (KeyboardHardware.isKeyMasked(row, col)) {
if (keyToggledOff(keyState)) {
KeyboardHardware.unMaskKey(row, col);
}
return;
}
for (byte i = 0; Kaleidoscope.eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
Kaleidoscope_::eventHandlerHook handler = Kaleidoscope.eventHandlers[i];
mappedKey = (*handler)(mappedKey, row, col, keyState);

@ -28,6 +28,23 @@ static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
} else {
Layer.off(target);
}
/*
* When toggling a layer off, we mask all keys still held. Masked keys
* will be ignored until released and pressed again (see
* `handleKeyswitchEvent` in key_events.cpp).
*
* We do this because when holding a momentary layer switch key, then
* pressing and holding some others, they will fire as keys on the
* momentary layer. But if we release the momentary layer switch key
* before releasing the others, they will continue firing, but from
* another layer. When typing fast, it may easily happen that we end up in
* a situation where the layer key releases first (in the same scan cycle,
* but handled first), and it will emit a key from the wrong layer. So we
* ignore held keys after releasing a layer key, until they are pressed
* again, to avoid the aforementioned issue.
*/
KeyboardHardware.maskHeldKeys();
}
// switch keymap and stay there

Loading…
Cancel
Save