Kaleidoscope
key_events.h
Go to the documentation of this file.
1 #pragma once
2 #include <Arduino.h>
3 
4 #include KALEIDOSCOPE_HARDWARE_H
5 #include "key_defs.h"
6 #include "keyswitch_state.h"
7 
8 extern const Key keymaps[][ROWS][COLS];
9 
10 
11 // Code can use this macro on injected key events to signal that
12 // the event isn't tied to a specific physical keyswitch
13 #define UNKNOWN_KEYSWITCH_LOCATION 255,255
14 
15 // sending events to the computer
16 /* The event handling starts with the Scanner calling handleKeyswitchEvent() for
17  * every key in the matrix, and it is the task of this method to figure out what
18  * to do, it is the main entry point.
19  *
20  * This function will iterate through an array of handler functions, and stop as
21  * soon as one of them signals that the event has been handled. To make it
22  * possible to inject synthetic events, one can call handleKeyswitchEvent from
23  * within a custom handler (making the event handling recursive), with a
24  * different keycode.
25  *
26  * This is useful for example for one-shot modifiers, where we would like to
27  * temporarily disable the one-shot functionality, and have them work as a
28  * normal modifier instead. In this case, the keymap would contain a key with
29  * OSM flags set, and the event handler would remove the OSM flags, and let the
30  * system handle the key as it would have, without the OSM flags. So we simply
31  * clear the flags, and call handleKeyswitchEvent again, with the modifier keycode
32  * as the first argument. This way, we could insert an event, and have the whole
33  * chain re-process it, instead of registering the keycode ourselves with HID
34  * ourselves. Injecting allows any and all custom handlers to have a chance,
35  * too.
36  *
37  * For this reason, the handleKeyswitchEvent receives four arguments: the mapped key
38  * (or Key_NoKey if we do not want to override what is in the keymap), the row
39  * and column of the key, so we can look up the code for it, and the current and
40  * previous state of the key, so we can determine what the event is. The
41  * currentState may be flagged INJECTED, which signals that the event was
42  * injected, and is not a direct result of a keypress, coming from the scanner.
43  */
44 void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState);
45 
#define ROWS
Definition: Kaleidoscope-Hardware-Model01.h:9
void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState)
Definition: key_events.cpp:46
byte byte col
Definition: TapDance.cpp:229
Definition: key_defs.h:13
#define COLS
Definition: Kaleidoscope-Hardware-Model01.h:8
byte row
Definition: TapDance.cpp:229
const Key keymaps[][ROWS][COLS]
uint8_t keyState
Definition: Kaleidoscope-Macros.cpp:5