diff --git a/src/key_events.h b/src/key_events.h index 9efe45af..c59b9afa 100644 --- a/src/key_events.h +++ b/src/key_events.h @@ -39,7 +39,9 @@ extern const Key keymaps[][ROWS][COLS]; * For this reason, the handle_key_event receives four arguments: the mapped key * (or Key_NoKey if we do not want to override what is in the keymap), the row * and column of the key, so we can look up the code for it, and the current and - * previous state of the key, so we can determine what the event is. + * previous state of the key, so we can determine what the event is. The + * currentState may be flagged INJECTED, which signals that the event was + * injected, and is not a direct result of a keypress, coming from the scanner. */ void handle_key_event(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState); diff --git a/src/keyswitch_state.cpp b/src/keyswitch_state.cpp index 90ea9cbb..d35a4569 100644 --- a/src/keyswitch_state.cpp +++ b/src/keyswitch_state.cpp @@ -11,7 +11,7 @@ boolean key_was_pressed (byte keyState) { } boolean key_was_pressed (uint8_t currentState, uint8_t previousState) { - if (previousState) { + if (previousState & B00000001) { return true; } else { return false; @@ -27,7 +27,7 @@ boolean key_is_pressed (byte keyState) { } boolean key_is_pressed (uint8_t currentState, uint8_t previousState) { - if (currentState) { + if (currentState & B00000001) { return true; } else { return false; @@ -43,7 +43,7 @@ boolean key_toggled_on(byte keyState) { } boolean key_toggled_on (uint8_t currentState, uint8_t previousState) { - if (currentState && ! previousState ) { + if ((currentState & B00000001) && ! (previousState & B00000001) ) { return true; } else { return false; @@ -60,7 +60,7 @@ boolean key_toggled_off(byte keyState) { } boolean key_toggled_off (uint8_t currentState, uint8_t previousState) { - if (previousState && ! currentState ) { + if ((previousState & B00000001) && ! (currentState & B00000001) ) { return true; } else { return false; diff --git a/src/keyswitch_state.h b/src/keyswitch_state.h index 13aa82d9..810b4e68 100644 --- a/src/keyswitch_state.h +++ b/src/keyswitch_state.h @@ -3,6 +3,7 @@ #include +#define INJECTED B10000000 boolean key_was_pressed (byte keyState); boolean key_is_pressed (byte keyState);