Add an INJECTED flag for keyswitch states

The INJECTED flag can be used by handlers to determine where the event
originated from: as a result of a direct keypress, or if it was injected
into the event loop some other way.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/56/head
Gergely Nagy 8 years ago
parent 06d38a1bda
commit ad7f645e01

@ -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);

@ -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;

@ -3,6 +3,7 @@
#include <Arduino.h>
#define INJECTED B10000000
boolean key_was_pressed (byte keyState);
boolean key_is_pressed (byte keyState);

Loading…
Cancel
Save