Kaleidoscope
key_defs.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include "HIDTables.h"
5 
6 #include "key_defs_keyboard.h"
7 #include "key_defs_sysctl.h"
8 #include "key_defs_consumerctl.h"
9 
10 #include "KeyboardioHID.h"
11 
12 
13 typedef union Key_ {
14 
15  struct {
16  uint8_t keyCode;
17  uint8_t flags;
18  };
19  uint16_t raw;
20 
21  inline bool operator==(uint16_t rhs) {
22  return this->raw == rhs;
23  }
24  inline bool operator==(const Key_ rhs) {
25  return this->raw == rhs.raw;
26  }
27  inline Key_& operator=(uint16_t raw) {
28  this->raw = raw;
29  return *this;
30  }
31  inline bool operator!=(const Key_& rhs) {
32  return !(*this == rhs);
33  }
34  inline bool operator>=(uint16_t raw) {
35  return this->raw >= raw;
36  }
37  inline bool operator<=(uint16_t raw) {
38  return this->raw <= raw;
39  }
40  inline bool operator>(uint16_t raw) {
41  return this->raw > raw;
42  }
43  inline bool operator<(uint16_t raw) {
44  return this->raw < raw;
45  }
46  inline bool operator>=(const Key_& other) {
47  return this->raw >= other.raw;
48  }
49  inline bool operator<=(const Key_& other) {
50  return this->raw <= other.raw;
51  }
52  inline bool operator>(const Key_& other) {
53  return this->raw > other.raw;
54  }
55  inline bool operator<(const Key_& other) {
56  return this->raw < other.raw;
57  }
58 } Key;
59 
60 
61 
62 #define KEY_FLAGS B00000000
63 #define CTRL_HELD B00000001
64 #define LALT_HELD B00000010
65 #define RALT_HELD B00000100
66 #define SHIFT_HELD B00001000
67 #define GUI_HELD B00010000
68 #define SYNTHETIC B01000000
69 #define RESERVED B10000000
70 
71 #define LCTRL(k) ((Key) { k.keyCode, k.flags | CTRL_HELD })
72 #define LALT(k) ((Key) { k.keyCode, k.flags | LALT_HELD })
73 #define RALT(k) ((Key) { k.keyCode, k.flags | RALT_HELD })
74 #define LSHIFT(k) ((Key) { k.keyCode, k.flags | SHIFT_HELD })
75 #define LGUI(k) ((Key) { k.keyCode, k.flags | GUI_HELD })
76 
77 // we assert that synthetic keys can never have keys held, so we reuse the _HELD bits
78 #define IS_SYSCTL B00000001
79 #define IS_CONSUMER B00000010
80 #define SWITCH_TO_KEYMAP B00000100
81 #define IS_INTERNAL B00001000
82 
83 /* HID types we need to encode in the key flags for system and consumer control hid controls
84  Each key can only have one, so we don't need to use a bit vector.
85  We need to keep the top two bits clear for defining the keys as synthetic
86  We need to keep the bottom two bits clear for defining the keys as sysctl / consumerctl
87 */
88 
89 #define HID_TYPE_CL B00000000
90 #define HID_TYPE_LC B00000100
91 #define HID_TYPE_NARY B00001000
92 #define HID_TYPE_OOC B00001100
93 #define HID_TYPE_OSC B00010000
94 #define HID_TYPE_RTC B00010100
95 #define HID_TYPE_SEL B00011000
96 
97 #define MOMENTARY_OFFSET 42
98 
99 #define KEYMAP_0 0
100 #define KEYMAP_1 1
101 #define KEYMAP_2 2
102 #define KEYMAP_3 3
103 #define KEYMAP_4 4
104 #define KEYMAP_5 5
105 #define KEYMAP_6 6
106 #define KEYMAP_7 7
107 
108 
109 #define KEYMAP_PREVIOUS 33
110 #define KEYMAP_NEXT 34
111 
112 
113 #define Key_NoKey (Key) { 0, KEY_FLAGS }
114 #define Key_skip (Key) { 0, KEY_FLAGS }
115 #define Key_Transparent (Key){ .raw = 0xffff }
116 #define ___ Key_Transparent
117 #define XXX Key_NoKey
118 
119 
120 
121 
122 #define Key_LeftParen LSHIFT(Key_9)
123 #define Key_RightParen LSHIFT(Key_0)
124 #define Key_LeftCurlyBracket LSHIFT(Key_LeftBracket)
125 #define Key_RightCurlyBracket LSHIFT(Key_RightBracket)
126 
127 #define Key_Pipe LSHIFT(Key_Backslash)
128 
129 
130 
131 #define KEY_BACKLIGHT_DOWN 0xF1
132 #define KEY_BACKLIGHT_UP 0xF2
133 #define Key_BacklightDown (Key) { KEY_BACKLIGHT_DOWN, KEY_FLAGS }
134 #define Key_BacklightUp (Key) { KEY_BACKLIGHT_UP, KEY_FLAGS }
135 #define KEY_RIGHT_FN2 0xfe
136 #define Key_RFN2 (Key) { KEY_RIGHT_FN2, KEY_FLAGS }
137 #define KEY_LEFT_FN2 0xff
138 #define Key_LFN2 (Key) { KEY_LEFT_FN2, KEY_FLAGS }
139 
140 #define Key_Keymap0 (Key) { KEYMAP_0, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
141 #define Key_Keymap1 (Key) { KEYMAP_1, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
142 #define Key_Keymap2 (Key) { KEYMAP_2, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
143 #define Key_Keymap3 (Key) { KEYMAP_3, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
144 #define Key_Keymap4 (Key) { KEYMAP_4, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
145 #define Key_Keymap5 (Key) { KEYMAP_5, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
146 #define Key_Keymap0_Momentary (Key){ KEYMAP_0 + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
147 #define Key_Keymap1_Momentary (Key){ KEYMAP_1 + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
148 #define Key_Keymap2_Momentary (Key){ KEYMAP_2 + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
149 #define Key_Keymap3_Momentary (Key){ KEYMAP_3 + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
150 #define Key_Keymap4_Momentary (Key){ KEYMAP_4 + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
151 #define Key_Keymap5_Momentary (Key){ KEYMAP_5 + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
152 
153 #define Key_KeymapNext_Momentary (Key) { KEYMAP_NEXT + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
154 #define Key_KeymapPrevious_Momentary (Key) { KEYMAP_PREVIOUS + MOMENTARY_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP }
uint16_t raw
Definition: key_defs.h:19
uint8_t keyCode
Definition: key_defs.h:16
bool operator>(const Key_ &other)
Definition: key_defs.h:52
bool operator!=(const Key_ &rhs)
Definition: key_defs.h:31
bool operator<(uint16_t raw)
Definition: key_defs.h:43
Definition: key_defs.h:13
uint8_t flags
Definition: key_defs.h:17
Key_ & operator=(uint16_t raw)
Definition: key_defs.h:27
bool operator<=(const Key_ &other)
Definition: key_defs.h:49
union Key_ Key
bool operator>=(uint16_t raw)
Definition: key_defs.h:34
bool operator==(const Key_ rhs)
Definition: key_defs.h:24
bool operator<(const Key_ &other)
Definition: key_defs.h:55
bool operator==(uint16_t rhs)
Definition: key_defs.h:21
bool operator>(uint16_t raw)
Definition: key_defs.h:40
bool operator<=(uint16_t raw)
Definition: key_defs.h:37
bool operator>=(const Key_ &other)
Definition: key_defs.h:46