Skip to content

Commit 69233de

Browse files
committed
Make key events exhaustive.
Means we can add keys without breaking backwards compatibility. KeyEvents are also manually numbered to discourage anyone adding one in the middle instead of at the end.
1 parent a1dd647 commit 69233de

File tree

1 file changed

+124
-122
lines changed

1 file changed

+124
-122
lines changed

src/lib.rs

Lines changed: 124 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -67,132 +67,134 @@ pub enum Error {
6767

6868
/// Keycodes that can be generated by a keyboard.
6969
#[derive(Debug, PartialEq, Eq, Copy, Clone, PartialOrd, Ord)]
70+
#[non_exhaustive]
7071
pub enum KeyCode {
71-
AltLeft,
72-
AltRight,
73-
ArrowDown,
74-
ArrowLeft,
75-
ArrowRight,
76-
ArrowUp,
77-
BackSlash,
78-
Backspace,
79-
BackTick,
80-
BracketSquareLeft,
81-
BracketSquareRight,
82-
Break,
83-
CapsLock,
84-
Comma,
85-
ControlLeft,
86-
ControlRight,
87-
Delete,
88-
End,
89-
Enter,
90-
Escape,
91-
Equals,
92-
F1,
93-
F2,
94-
F3,
95-
F4,
96-
F5,
97-
F6,
98-
F7,
99-
F8,
100-
F9,
101-
F10,
102-
F11,
103-
F12,
104-
Fullstop,
105-
Home,
106-
Insert,
107-
Key1,
108-
Key2,
109-
Key3,
110-
Key4,
111-
Key5,
112-
Key6,
113-
Key7,
114-
Key8,
115-
Key9,
116-
Key0,
117-
Menus,
118-
Minus,
119-
Numpad0,
120-
Numpad1,
121-
Numpad2,
122-
Numpad3,
123-
Numpad4,
124-
Numpad5,
125-
Numpad6,
126-
Numpad7,
127-
Numpad8,
128-
Numpad9,
129-
NumpadEnter,
130-
NumpadLock,
131-
NumpadSlash,
132-
NumpadStar,
133-
NumpadMinus,
134-
NumpadPeriod,
135-
NumpadPlus,
136-
PageDown,
137-
PageUp,
138-
PauseBreak,
139-
PrintScreen,
140-
ScrollLock,
141-
SemiColon,
142-
ShiftLeft,
143-
ShiftRight,
144-
Slash,
145-
Spacebar,
146-
SysReq,
147-
Tab,
148-
Quote,
149-
WindowsLeft,
150-
WindowsRight,
151-
A,
152-
B,
153-
C,
154-
D,
155-
E,
156-
F,
157-
G,
158-
H,
159-
I,
160-
J,
161-
K,
162-
L,
163-
M,
164-
N,
165-
O,
166-
P,
167-
Q,
168-
R,
169-
S,
170-
T,
171-
U,
172-
V,
173-
W,
174-
X,
175-
Y,
176-
Z,
177-
/// Not on US keyboards
178-
HashTilde,
72+
AltLeft = 0,
73+
AltRight = 1,
74+
ArrowDown = 2,
75+
ArrowLeft = 3,
76+
ArrowRight = 4,
77+
ArrowUp = 5,
78+
BackSlash = 6,
79+
Backspace = 7,
80+
BackTick = 8,
81+
BracketSquareLeft = 9,
82+
BracketSquareRight = 10,
83+
Break = 11,
84+
CapsLock = 12,
85+
Comma = 13,
86+
ControlLeft = 14,
87+
ControlRight = 15,
88+
Delete = 16,
89+
End = 17,
90+
Enter = 18,
91+
Escape = 19,
92+
Equals = 20,
93+
F1 = 21,
94+
F2 = 22,
95+
F3 = 23,
96+
F4 = 24,
97+
F5 = 26,
98+
F6 = 27,
99+
F7 = 28,
100+
F8 = 29,
101+
F9 = 30,
102+
F10 = 31,
103+
F11 = 32,
104+
F12 = 33,
105+
Fullstop = 34,
106+
Home = 36,
107+
Insert = 37,
108+
Key1 = 38,
109+
Key2 = 39,
110+
Key3 = 40,
111+
Key4 = 41,
112+
Key5 = 42,
113+
Key6 = 43,
114+
Key7 = 44,
115+
Key8 = 46,
116+
Key9 = 47,
117+
Key0 = 48,
118+
Menus = 49,
119+
Minus = 50,
120+
Numpad0 = 51,
121+
Numpad1 = 52,
122+
Numpad2 = 53,
123+
Numpad3 = 54,
124+
Numpad4 = 56,
125+
Numpad5 = 57,
126+
Numpad6 = 58,
127+
Numpad7 = 59,
128+
Numpad8 = 60,
129+
Numpad9 = 61,
130+
NumpadEnter = 62,
131+
NumpadLock = 63,
132+
NumpadSlash = 64,
133+
NumpadStar = 66,
134+
NumpadMinus = 67,
135+
NumpadPeriod = 68,
136+
NumpadPlus = 69,
137+
PageDown = 70,
138+
PageUp = 71,
139+
PauseBreak = 72,
140+
PrintScreen = 73,
141+
ScrollLock = 74,
142+
SemiColon = 76,
143+
ShiftLeft = 77,
144+
ShiftRight = 78,
145+
Slash = 79,
146+
Spacebar = 80,
147+
SysReq = 81,
148+
Tab = 82,
149+
Quote = 83,
150+
WindowsLeft = 84,
151+
WindowsRight = 86,
152+
A = 87,
153+
B = 88,
154+
C = 89,
155+
D = 90,
156+
E = 91,
157+
F = 92,
158+
G = 93,
159+
H = 94,
160+
I = 96,
161+
J = 97,
162+
K = 98,
163+
L = 99,
164+
M = 100,
165+
N = 101,
166+
O = 102,
167+
P = 103,
168+
Q = 104,
169+
R = 106,
170+
S = 107,
171+
T = 108,
172+
U = 109,
173+
V = 110,
174+
W = 111,
175+
X = 112,
176+
Y = 113,
177+
Z = 114,
178+
/// The key to the left of the 102/105-key "Tall Return" Key - not on 101/104-key keyboards
179+
HashTilde = 115,
179180
// Scan code set 1 unique codes
180-
PrevTrack,
181-
NextTrack,
182-
Mute,
183-
Calculator,
184-
Play,
185-
Stop,
186-
VolumeDown,
187-
VolumeUp,
188-
WWWHome,
189-
// Sent when the keyboard boots
190-
PowerOnTestOk,
191-
Oem102,
181+
PrevTrack = 116,
182+
NextTrack = 117,
183+
Mute = 118,
184+
Calculator = 119,
185+
Play = 120,
186+
Stop = 121,
187+
VolumeDown = 122,
188+
VolumeUp = 123,
189+
WWWHome = 124,
190+
/// Sent when the keyboard boots
191+
PowerOnTestOk = 125,
192+
/// Used for `<>` on DE layouts
193+
Oem102 = 126,
192194
/// PrintScreen comes in two parts - this is the second
193-
PrintScreen2,
195+
PrintScreen2 = 127,
194196
/// Sent by the keyboard when too many keys are pressed
195-
TooManyKeys,
197+
TooManyKeys = 128,
196198
}
197199

198200
#[derive(Debug, PartialEq, Eq, Copy, Clone)]

0 commit comments

Comments
 (0)