Merge pull request #205 from cdisselkoen/inject-physical

Allow injected events tied to physical keyswitches
pull/271/head
Jesse Vincent 7 years ago committed by GitHub
commit 7a55a9395f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -45,13 +45,18 @@ void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
* In particular, doing them for keypresses with out-of-bounds (row,col) * In particular, doing them for keypresses with out-of-bounds (row,col)
* would cause out-of-bounds array accesses in Layer.lookup(), * would cause out-of-bounds array accesses in Layer.lookup(),
* Layer.updateLiveCompositeKeymap(), etc. * Layer.updateLiveCompositeKeymap(), etc.
* Perhaps this check should instead be for INJECTED - I'm not clear on * Note that many INJECTED keypresses use the UNKNOWN_KEYSWITCH_LOCATION macro
* whether keypresses with out-of-bounds (row,col) are the same as * which gives us row==255, col==255 here. Therefore, it's legitimate that
* keypresses with INJECTED set, or are a superset or a subset of * we may have keypresses with out-of-bounds (row, col).
* INJECTED keypresses. In any case, the (row,col) test is *safe* in that * However, some INJECTED keypresses do have valid (row, col) if they are
* it avoids out-of-bounds accesses, at least in core. (Can't promise * injecting an event tied to a physical keyswitch - and we want them to go
* anything about event handlers - they may still receive out-of-bounds * through this lookup.
* (row,col), and handling that properly is on them.) * So we can't just test for INJECTED here, we need to test the row and col
* directly.
* Note also that this (row, col) test avoids out-of-bounds accesses in *core*,
* but doesn't guarantee anything about event handlers - event handlers may
* still receive out-of-bounds (row, col), and handling that properly is on
* them.
*/ */
if (row < ROWS && col < COLS) { if (row < ROWS && col < COLS) {
@ -75,7 +80,11 @@ void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
} }
} }
if (!(keyState & INJECTED)) { /* Convert (row, col) to the correct mappedKey
* The condition here means that if mappedKey and (row, col) are both valid,
* the mappedKey wins - we don't re-look-up the mappedKey
*/
if (mappedKey.raw == Key_NoKey.raw) {
mappedKey = Layer.lookup(row, col); mappedKey = Layer.lookup(row, col);
} }

@ -11,6 +11,9 @@ extern const Key keymaps[][ROWS][COLS];
// Code can use this macro on injected key events to signal that // Code can use this macro on injected key events to signal that
// the event isn't tied to a specific physical keyswitch // the event isn't tied to a specific physical keyswitch
#define UNKNOWN_KEYSWITCH_LOCATION 255,255 #define UNKNOWN_KEYSWITCH_LOCATION 255,255
// Conversely, if an injected event *is* tied to a physical keyswitch and should
// be resolved by the current keymap, code can use Key_NoKey on the injected event
// with a real (row, col) location
// sending events to the computer // sending events to the computer
/* The event handling starts with the Scanner calling handleKeyswitchEvent() for /* The event handling starts with the Scanner calling handleKeyswitchEvent() for

Loading…
Cancel
Save