zng_view_api/keyboard.rs
1//! Keyboard types.
2
3use std::{fmt, mem};
4
5use serde::{Deserialize, Serialize};
6use zng_txt::Txt;
7
8/// The location of the key on the keyboard.
9///
10/// Certain physical keys on the keyboard can have the same value, but are in different locations.
11/// For instance, the Shift key can be on the left or right side of the keyboard, or the number
12/// keys can be above the letters or on the numpad. This enum allows the user to differentiate
13/// them.
14#[derive(Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
15#[repr(u8)]
16#[non_exhaustive]
17pub enum KeyLocation {
18 /// The key is in its "normal" location on the keyboard.
19 ///
20 /// For instance, the "1" key above the "Q" key on a QWERTY keyboard will use this location.
21 /// This invariant is also returned when the location of the key cannot be identified.
22 Standard,
23
24 /// The key is on the left side of the keyboard.
25 ///
26 /// For instance, the left Shift key below the Caps Lock key on a QWERTY keyboard will use this
27 /// location.
28 Left,
29
30 /// The key is on the right side of the keyboard.
31 ///
32 /// For instance, the right Shift key below the Enter key on a QWERTY keyboard will use this
33 /// location.
34 Right,
35
36 /// The key is on the numpad.
37 ///
38 /// For instance, the "1" key on the numpad will use this location.
39 Numpad,
40}
41impl KeyLocation {
42 /// Gets the variant name.
43 pub fn name(self) -> &'static str {
44 serde_variant::to_variant_name(&self).unwrap_or("")
45 }
46}
47impl std::fmt::Debug for KeyLocation {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 if f.alternate() {
50 write!(f, "KeyLocation::")?;
51 }
52 write!(f, "{}", self.name())
53 }
54}
55
56/// Contains the platform-native physical key identifier
57///
58/// The exact values vary from platform to platform (which is part of why this is a per-platform
59/// enum), but the values are primarily tied to the key's physical location on the keyboard.
60///
61/// This enum is primarily used to store raw key codes when Winit doesn't map a given native
62/// physical key identifier to a meaningful [`KeyCode`] variant. In the presence of identifiers we
63/// haven't mapped for you yet, this lets you use [`KeyCode`] to:
64///
65/// - Correctly match key press and release events.
66/// - On non-web platforms, support assigning key binds to virtually any key through a UI.
67#[derive(Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
68#[repr(u8)]
69#[non_exhaustive]
70pub enum NativeKeyCode {
71 /// Implementer did not identify system or scancode.
72 Unidentified,
73 /// An Android "scancode".
74 Android(u32),
75 /// A macOS "scancode".
76 MacOS(u16),
77 /// A Windows "scancode".
78 Windows(u16),
79 /// An XKB "keycode".
80 Xkb(u32),
81}
82impl NativeKeyCode {
83 /// Gets the variant name.
84 pub fn name(self) -> &'static str {
85 serde_variant::to_variant_name(&self).unwrap_or("")
86 }
87}
88impl std::fmt::Debug for NativeKeyCode {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 if f.alternate() {
91 write!(f, "NativeKeyCode::")?;
92 }
93
94 use NativeKeyCode::{Android, MacOS, Unidentified, Windows, Xkb};
95 let mut debug_tuple;
96 match self {
97 Unidentified => {
98 debug_tuple = f.debug_tuple("Unidentified");
99 }
100 Android(code) => {
101 debug_tuple = f.debug_tuple("Android");
102 debug_tuple.field(&format_args!("0x{code:04X}"));
103 }
104 MacOS(code) => {
105 debug_tuple = f.debug_tuple("MacOS");
106 debug_tuple.field(&format_args!("0x{code:04X}"));
107 }
108 Windows(code) => {
109 debug_tuple = f.debug_tuple("Windows");
110 debug_tuple.field(&format_args!("0x{code:04X}"));
111 }
112 Xkb(code) => {
113 debug_tuple = f.debug_tuple("Xkb");
114 debug_tuple.field(&format_args!("0x{code:04X}"));
115 }
116 }
117 debug_tuple.finish()
118 }
119}
120
121/// Represents the location of a physical key.
122///
123/// This mostly conforms to the UI Events Specification's [`KeyboardEvent.code`] with a few
124/// exceptions:
125/// - The keys that the specification calls "MetaLeft" and "MetaRight" are named "SuperLeft" and
126/// "SuperRight" here.
127/// - The key that the specification calls "Super" is reported as `Unidentified` here.
128/// - The `Unidentified` variant here, can still identify a key through it's `NativeKeyCode`.
129///
130/// [`KeyboardEvent.code`]: https://w3c.github.io/uievents-code/#code-value-tables
131#[non_exhaustive]
132#[derive(Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
133#[repr(u16)]
134pub enum KeyCode {
135 /* source: https://docs.rs/winit/0.29.0-beta.0/src/winit/keyboard.rs.html#201-649 */
136 /// This variant is used when the key cannot be translated to any other variant.
137 ///
138 /// The native keycode is provided (if available) so you're able to more reliably match
139 /// key-press and key-release events by hashing the [`KeyCode`]. It is also possible to use
140 /// this for key-binds for non-standard keys, but such key-binds are tied to a given platform.
141 Unidentified(NativeKeyCode),
142 /// <kbd>`</kbd> on a US keyboard. This is also called a backtick or grave.
143 /// This is the <kbd>半角</kbd>/<kbd>全角</kbd>/<kbd>漢字</kbd>
144 /// (hankaku/zenkaku/kanji) key on Japanese keyboards
145 Backquote = 1,
146 /// Used for both the US <kbd>\\</kbd> (on the 101-key layout) and also for the key
147 /// located between the <kbd>"</kbd> and <kbd>Enter</kbd> keys on row C of the 102-,
148 /// 104- and 106-key layouts.
149 /// Labeled <kbd>#</kbd> on a UK (102) keyboard.
150 Backslash,
151 /// <kbd>[</kbd> on a US keyboard.
152 BracketLeft,
153 /// <kbd>]</kbd> on a US keyboard.
154 BracketRight,
155 /// <kbd>,</kbd> on a US keyboard.
156 Comma,
157 /// <kbd>0</kbd> on a US keyboard.
158 Digit0,
159 /// <kbd>1</kbd> on a US keyboard.
160 Digit1,
161 /// <kbd>2</kbd> on a US keyboard.
162 Digit2,
163 /// <kbd>3</kbd> on a US keyboard.
164 Digit3,
165 /// <kbd>4</kbd> on a US keyboard.
166 Digit4,
167 /// <kbd>5</kbd> on a US keyboard.
168 Digit5,
169 /// <kbd>6</kbd> on a US keyboard.
170 Digit6,
171 /// <kbd>7</kbd> on a US keyboard.
172 Digit7,
173 /// <kbd>8</kbd> on a US keyboard.
174 Digit8,
175 /// <kbd>9</kbd> on a US keyboard.
176 Digit9,
177 /// <kbd>=</kbd> on a US keyboard.
178 Equal,
179 /// Located between the left <kbd>Shift</kbd> and <kbd>Z</kbd> keys.
180 /// Labeled <kbd>\\</kbd> on a UK keyboard.
181 IntlBackslash,
182 /// Located between the <kbd>/</kbd> and right <kbd>Shift</kbd> keys.
183 /// Labeled <kbd>\\</kbd> (ro) on a Japanese keyboard.
184 IntlRo,
185 /// Located between the <kbd>=</kbd> and <kbd>Backspace</kbd> keys.
186 /// Labeled <kbd>¥</kbd> (yen) on a Japanese keyboard. <kbd>\\</kbd> on a
187 /// Russian keyboard.
188 IntlYen,
189 /// <kbd>a</kbd> on a US keyboard.
190 /// Labeled <kbd>q</kbd> on an AZERTY (e.g., French) keyboard.
191 KeyA,
192 /// <kbd>b</kbd> on a US keyboard.
193 KeyB,
194 /// <kbd>c</kbd> on a US keyboard.
195 KeyC,
196 /// <kbd>d</kbd> on a US keyboard.
197 KeyD,
198 /// <kbd>e</kbd> on a US keyboard.
199 KeyE,
200 /// <kbd>f</kbd> on a US keyboard.
201 KeyF,
202 /// <kbd>g</kbd> on a US keyboard.
203 KeyG,
204 /// <kbd>h</kbd> on a US keyboard.
205 KeyH,
206 /// <kbd>i</kbd> on a US keyboard.
207 KeyI,
208 /// <kbd>j</kbd> on a US keyboard.
209 KeyJ,
210 /// <kbd>k</kbd> on a US keyboard.
211 KeyK,
212 /// <kbd>l</kbd> on a US keyboard.
213 KeyL,
214 /// <kbd>m</kbd> on a US keyboard.
215 KeyM,
216 /// <kbd>n</kbd> on a US keyboard.
217 KeyN,
218 /// <kbd>o</kbd> on a US keyboard.
219 KeyO,
220 /// <kbd>p</kbd> on a US keyboard.
221 KeyP,
222 /// <kbd>q</kbd> on a US keyboard.
223 /// Labeled <kbd>a</kbd> on an AZERTY (e.g., French) keyboard.
224 KeyQ,
225 /// <kbd>r</kbd> on a US keyboard.
226 KeyR,
227 /// <kbd>s</kbd> on a US keyboard.
228 KeyS,
229 /// <kbd>t</kbd> on a US keyboard.
230 KeyT,
231 /// <kbd>u</kbd> on a US keyboard.
232 KeyU,
233 /// <kbd>v</kbd> on a US keyboard.
234 KeyV,
235 /// <kbd>w</kbd> on a US keyboard.
236 /// Labeled <kbd>z</kbd> on an AZERTY (e.g., French) keyboard.
237 KeyW,
238 /// <kbd>x</kbd> on a US keyboard.
239 KeyX,
240 /// <kbd>y</kbd> on a US keyboard.
241 /// Labeled <kbd>z</kbd> on a QWERTZ (e.g., German) keyboard.
242 KeyY,
243 /// <kbd>z</kbd> on a US keyboard.
244 /// Labeled <kbd>w</kbd> on an AZERTY (e.g., French) keyboard, and <kbd>y</kbd> on a
245 /// QWERTZ (e.g., German) keyboard.
246 KeyZ,
247 /// <kbd>-</kbd> on a US keyboard.
248 Minus,
249 /// <kbd>.</kbd> on a US keyboard.
250 Period,
251 /// <kbd>'</kbd> on a US keyboard.
252 Quote,
253 /// <kbd>;</kbd> on a US keyboard.
254 Semicolon,
255 /// <kbd>/</kbd> on a US keyboard.
256 Slash,
257 /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
258 AltLeft,
259 /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
260 /// This is labelled <kbd>AltGr</kbd> on many keyboard layouts.
261 AltRight,
262 /// <kbd>Backspace</kbd> or <kbd>⌫</kbd>.
263 /// Labeled <kbd>Delete</kbd> on Apple keyboards.
264 Backspace,
265 /// <kbd>CapsLock</kbd> or <kbd>⇪</kbd>
266 CapsLock,
267 /// The application context menu key, which is typically found between the right
268 /// <kbd>Super</kbd> key and the right <kbd>Ctrl</kbd> key.
269 ContextMenu,
270 /// <kbd>Ctrl</kbd> or <kbd>⌃</kbd>
271 CtrlLeft,
272 /// <kbd>Ctrl</kbd> or <kbd>⌃</kbd>
273 CtrlRight,
274 /// <kbd>Enter</kbd> or <kbd>↵</kbd>. Labeled <kbd>Return</kbd> on Apple keyboards.
275 Enter,
276 /// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
277 SuperLeft,
278 /// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
279 SuperRight,
280 /// <kbd>Shift</kbd> or <kbd>⇧</kbd>
281 ShiftLeft,
282 /// <kbd>Shift</kbd> or <kbd>⇧</kbd>
283 ShiftRight,
284 /// <kbd> </kbd> (space)
285 Space,
286 /// <kbd>Tab</kbd> or <kbd>⇥</kbd>
287 Tab,
288 /// Japanese: <kbd>変</kbd> (henkan)
289 Convert,
290 /// Japanese: <kbd>カタカナ</kbd>/<kbd>ひらがな</kbd>/<kbd>ローマ字</kbd> (katakana/hiragana/romaji)
291 KanaMode,
292 /// Korean: HangulMode <kbd>한/영</kbd> (han/yeong)
293 ///
294 /// Japanese (Mac keyboard): <kbd>か</kbd> (kana)
295 Lang1,
296 /// Korean: Hanja <kbd>한</kbd> (hanja)
297 ///
298 /// Japanese (Mac keyboard): <kbd>英</kbd> (eisu)
299 Lang2,
300 /// Japanese (word-processing keyboard): Katakana
301 Lang3,
302 /// Japanese (word-processing keyboard): Hiragana
303 Lang4,
304 /// Japanese (word-processing keyboard): Zenkaku/Hankaku
305 Lang5,
306 /// Japanese: <kbd>無変換</kbd> (muhenkan)
307 NonConvert,
308 /// <kbd>⌦</kbd>. The forward delete key.
309 /// Note that on Apple keyboards, the key labelled <kbd>Delete</kbd> on the main part of
310 /// the keyboard is encoded as [`Backspace`].
311 ///
312 /// [`Backspace`]: Self::Backspace
313 Delete,
314 /// <kbd>Page Down</kbd>, <kbd>End</kbd>, or <kbd>↘</kbd>
315 End,
316 /// <kbd>Help</kbd>. Not present on standard PC keyboards.
317 Help,
318 /// <kbd>Home</kbd> or <kbd>↖</kbd>
319 Home,
320 /// <kbd>Insert</kbd> or <kbd>Ins</kbd>. Not present on Apple keyboards.
321 Insert,
322 /// <kbd>Page Down</kbd>, <kbd>PgDn</kbd>, or <kbd>⇟</kbd>
323 PageDown,
324 /// <kbd>Page Up</kbd>, <kbd>PgUp</kbd>, or <kbd>⇞</kbd>
325 PageUp,
326 /// <kbd>↓</kbd>
327 ArrowDown,
328 /// <kbd>←</kbd>
329 ArrowLeft,
330 /// <kbd>→</kbd>
331 ArrowRight,
332 /// <kbd>↑</kbd>
333 ArrowUp,
334 /// On the Mac, this is used for the numpad <kbd>Clear</kbd> key.
335 NumLock,
336 /// <kbd>0 Ins</kbd> on a keyboard. <kbd>0</kbd> on a phone or remote control
337 Numpad0,
338 /// <kbd>1 End</kbd> on a keyboard. <kbd>1</kbd> or <kbd>1 QZ</kbd> on a phone or remote control
339 Numpad1,
340 /// <kbd>2 ↓</kbd> on a keyboard. <kbd>2 ABC</kbd> on a phone or remote control
341 Numpad2,
342 /// <kbd>3 PgDn</kbd> on a keyboard. <kbd>3 DEF</kbd> on a phone or remote control
343 Numpad3,
344 /// <kbd>4 ←</kbd> on a keyboard. <kbd>4 GHI</kbd> on a phone or remote control
345 Numpad4,
346 /// <kbd>5</kbd> on a keyboard. <kbd>5 JKL</kbd> on a phone or remote control
347 Numpad5,
348 /// <kbd>6 →</kbd> on a keyboard. <kbd>6 MNO</kbd> on a phone or remote control
349 Numpad6,
350 /// <kbd>7 Home</kbd> on a keyboard. <kbd>7 PQRS</kbd> or <kbd>7 PRS</kbd> on a phone
351 /// or remote control
352 Numpad7,
353 /// <kbd>8 ↑</kbd> on a keyboard. <kbd>8 TUV</kbd> on a phone or remote control
354 Numpad8,
355 /// <kbd>9 PgUp</kbd> on a keyboard. <kbd>9 WXYZ</kbd> or <kbd>9 WXY</kbd> on a phone
356 /// or remote control
357 Numpad9,
358 /// <kbd>+</kbd>
359 NumpadAdd,
360 /// Found on the Microsoft Natural Keyboard.
361 NumpadBackspace,
362 /// <kbd>C</kbd> or <kbd>A</kbd> (All Clear). Also for use with numpads that have a
363 /// <kbd>Clear</kbd> key that is separate from the <kbd>NumLock</kbd> key. On the Mac, the
364 /// numpad <kbd>Clear</kbd> key is encoded as [`NumLock`].
365 ///
366 /// [`NumLock`]: Self::NumLock
367 NumpadClear,
368 /// <kbd>C</kbd> (Clear Entry)
369 NumpadClearEntry,
370 /// <kbd>,</kbd> (thousands separator). For locales where the thousands separator
371 /// is a "." (e.g., Brazil), this key may generate a <kbd>.</kbd>.
372 NumpadComma,
373 /// <kbd>. Del</kbd>. For locales where the decimal separator is "," (e.g.,
374 /// Brazil), this key may generate a <kbd>,</kbd>.
375 NumpadDecimal,
376 /// <kbd>/</kbd>
377 NumpadDivide,
378 /// <kbd>↵</kbd>
379 NumpadEnter,
380 /// <kbd>=</kbd>
381 NumpadEqual,
382 /// <kbd>#</kbd> on a phone or remote control device. This key is typically found
383 /// below the <kbd>9</kbd> key and to the right of the <kbd>0</kbd> key.
384 NumpadHash,
385 /// <kbd>M</kbd> Add current entry to the value stored in memory.
386 NumpadMemoryAdd,
387 /// <kbd>M</kbd> Clear the value stored in memory.
388 NumpadMemoryClear,
389 /// <kbd>M</kbd> Replace the current entry with the value stored in memory.
390 NumpadMemoryRecall,
391 /// <kbd>M</kbd> Replace the value stored in memory with the current entry.
392 NumpadMemoryStore,
393 /// <kbd>M</kbd> Subtract current entry from the value stored in memory.
394 NumpadMemorySubtract,
395 /// <kbd>*</kbd> on a keyboard. For use with numpads that provide mathematical
396 /// operations (<kbd>+</kbd>, <kbd>-</kbd> <kbd>*</kbd> and <kbd>/</kbd>).
397 ///
398 /// Use `NumpadStar` for the <kbd>*</kbd> key on phones and remote controls.
399 NumpadMultiply,
400 /// <kbd>(</kbd> Found on the Microsoft Natural Keyboard.
401 NumpadParenLeft,
402 /// <kbd>)</kbd> Found on the Microsoft Natural Keyboard.
403 NumpadParenRight,
404 /// <kbd>*</kbd> on a phone or remote control device.
405 ///
406 /// This key is typically found below the <kbd>7</kbd> key and to the left of
407 /// the <kbd>0</kbd> key.
408 ///
409 /// Use <kbd>"NumpadMultiply"</kbd> for the <kbd>*</kbd> key on
410 /// numeric keypads.
411 NumpadStar,
412 /// <kbd>-</kbd>
413 NumpadSubtract,
414 /// <kbd>Esc</kbd> or <kbd>⎋</kbd>
415 Escape,
416 /// <kbd>Fn</kbd> This is typically a hardware key that does not generate a separate code.
417 Fn,
418 /// <kbd>FLock</kbd> or <kbd>FnLock</kbd>. Function Lock key. Found on the Microsoft
419 /// Natural Keyboard.
420 FnLock,
421 /// <kbd>PrtScr SysRq</kbd> or <kbd>Print Screen</kbd>
422 PrintScreen,
423 /// <kbd>Scroll Lock</kbd>
424 ScrollLock,
425 /// <kbd>Pause Break</kbd>
426 Pause,
427 /// Some laptops place this key to the left of the <kbd>↑</kbd> key.
428 ///
429 /// This also the "back" button (triangle) on Android.
430 BrowserBack,
431 /// Browser Favorites key.
432 BrowserFavorites,
433 /// Some laptops place this key to the right of the <kbd>↑</kbd> key.
434 BrowserForward,
435 /// The "home" button on Android.
436 BrowserHome,
437 /// Browser Refresh key.
438 BrowserRefresh,
439 /// Browser Search key.
440 BrowserSearch,
441 /// Browser Search key.
442 BrowserStop,
443 /// <kbd>Eject</kbd> or <kbd>⏏</kbd>. This key is placed in the function section on some Apple
444 /// keyboards.
445 Eject,
446 /// Sometimes labelled <kbd>My Computer</kbd> on the keyboard
447 LaunchApp1,
448 /// Sometimes labelled <kbd>Calculator</kbd> on the keyboard
449 LaunchApp2,
450 /// <kbd>✉</kbd>
451 LaunchMail,
452 /// <kbd>⏯</kbd>
453 MediaPlayPause,
454 /// Select Media key.
455 MediaSelect,
456 /// <kbd>⏹</kbd>
457 MediaStop,
458 /// <kbd>⏭</kbd>
459 MediaTrackNext,
460 /// <kbd>⏮</kbd>
461 MediaTrackPrevious,
462 /// This key is placed in the function section on some Apple keyboards, replacing the
463 /// <kbd>Eject</kbd> key.
464 Power,
465 /// Computer Sleep key.
466 Sleep,
467 /// Volume Down key.
468 AudioVolumeDown,
469 /// Volume Mute key.
470 AudioVolumeMute,
471 /// Volume Up key.
472 AudioVolumeUp,
473 /// Wakes up the device if it is not already awake.
474 WakeUp,
475 /// Legacy modifier key. Also called "Super" in certain places.
476 Meta,
477 /// Legacy modifier key.
478 Hyper,
479 /// Legacy under-clock key.
480 Turbo,
481 /// Legacy abort key.
482 Abort,
483 /// Legacy resume key.
484 Resume,
485 /// Legacy suspend key.
486 Suspend,
487 /// Found on Sun’s USB keyboard.
488 Again,
489 /// Found on Sun’s USB keyboard.
490 Copy,
491 /// Found on Sun’s USB keyboard.
492 Cut,
493 /// Found on Sun’s USB keyboard.
494 Find,
495 /// Found on Sun’s USB keyboard.
496 Open,
497 /// Found on Sun’s USB keyboard.
498 Paste,
499 /// Found on Sun’s USB keyboard.
500 Props,
501 /// Found on Sun’s USB keyboard.
502 Select,
503 /// Found on Sun’s USB keyboard.
504 Undo,
505 /// Use for dedicated <kbd>ひらがな</kbd> key found on some Japanese word processing keyboards.
506 Hiragana,
507 /// Use for dedicated <kbd>カタカナ</kbd> key found on some Japanese word processing keyboards.
508 Katakana,
509 /// General-purpose function key.
510 /// Usually found at the top of the keyboard.
511 F1,
512 /// General-purpose function key.
513 /// Usually found at the top of the keyboard.
514 F2,
515 /// General-purpose function key.
516 /// Usually found at the top of the keyboard.
517 F3,
518 /// General-purpose function key.
519 /// Usually found at the top of the keyboard.
520 F4,
521 /// General-purpose function key.
522 /// Usually found at the top of the keyboard.
523 F5,
524 /// General-purpose function key.
525 /// Usually found at the top of the keyboard.
526 F6,
527 /// General-purpose function key.
528 /// Usually found at the top of the keyboard.
529 F7,
530 /// General-purpose function key.
531 /// Usually found at the top of the keyboard.
532 F8,
533 /// General-purpose function key.
534 /// Usually found at the top of the keyboard.
535 F9,
536 /// General-purpose function key.
537 /// Usually found at the top of the keyboard.
538 F10,
539 /// General-purpose function key.
540 /// Usually found at the top of the keyboard.
541 F11,
542 /// General-purpose function key.
543 /// Usually found at the top of the keyboard.
544 F12,
545 /// General-purpose function key.
546 /// Usually found at the top of the keyboard.
547 F13,
548 /// General-purpose function key.
549 /// Usually found at the top of the keyboard.
550 F14,
551 /// General-purpose function key.
552 /// Usually found at the top of the keyboard.
553 F15,
554 /// General-purpose function key.
555 /// Usually found at the top of the keyboard.
556 F16,
557 /// General-purpose function key.
558 /// Usually found at the top of the keyboard.
559 F17,
560 /// General-purpose function key.
561 /// Usually found at the top of the keyboard.
562 F18,
563 /// General-purpose function key.
564 /// Usually found at the top of the keyboard.
565 F19,
566 /// General-purpose function key.
567 /// Usually found at the top of the keyboard.
568 F20,
569 /// General-purpose function key.
570 /// Usually found at the top of the keyboard.
571 F21,
572 /// General-purpose function key.
573 /// Usually found at the top of the keyboard.
574 F22,
575 /// General-purpose function key.
576 /// Usually found at the top of the keyboard.
577 F23,
578 /// General-purpose function key.
579 /// Usually found at the top of the keyboard.
580 F24,
581 /// General-purpose function key.
582 F25,
583 /// General-purpose function key.
584 F26,
585 /// General-purpose function key.
586 F27,
587 /// General-purpose function key.
588 F28,
589 /// General-purpose function key.
590 F29,
591 /// General-purpose function key.
592 F30,
593 /// General-purpose function key.
594 F31,
595 /// General-purpose function key.
596 F32,
597 /// General-purpose function key.
598 F33,
599 /// General-purpose function key.
600 F34,
601 /// General-purpose function key.
602 F35,
603}
604impl Clone for KeyCode {
605 fn clone(&self) -> Self {
606 *self
607 }
608}
609impl KeyCode {
610 /// If key-code is fully unidentified ([`NativeKeyCode::Unidentified`]).
611 pub fn is_unidentified(&self) -> bool {
612 matches!(self, KeyCode::Unidentified(NativeKeyCode::Unidentified))
613 }
614
615 /// If the keycode represents a known and identified modifier.
616 pub fn is_modifier(&self) -> bool {
617 matches!(
618 self,
619 KeyCode::AltLeft
620 | KeyCode::AltRight
621 | KeyCode::CtrlLeft
622 | KeyCode::CtrlRight
623 | KeyCode::ShiftLeft
624 | KeyCode::ShiftRight
625 | KeyCode::SuperLeft
626 | KeyCode::SuperRight
627 | KeyCode::CapsLock
628 | KeyCode::Fn
629 | KeyCode::FnLock
630 | KeyCode::Meta
631 | KeyCode::NumLock
632 | KeyCode::ScrollLock
633 | KeyCode::Hyper
634 )
635 }
636
637 /// If the key if for IME composition actions as defined by [w3].
638 ///
639 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-composition
640 pub fn is_composition(&self) -> bool {
641 matches!(self, |KeyCode::Convert| KeyCode::NonConvert
642 | KeyCode::Hiragana
643 | KeyCode::KanaMode
644 | KeyCode::Katakana)
645 }
646
647 /// If the key is for an edit action as defined by [w3].
648 ///
649 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-editing
650 pub fn is_editing(&self) -> bool {
651 matches!(
652 self,
653 KeyCode::Backspace | KeyCode::Cut | KeyCode::Delete | KeyCode::Insert | KeyCode::Paste | KeyCode::Undo
654 )
655 }
656
657 /// If the key is for an general UI action as defined by [w3].
658 ///
659 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-ui
660 pub fn is_ui(&self) -> bool {
661 matches!(
662 self,
663 KeyCode::Again
664 | KeyCode::ContextMenu
665 | KeyCode::Escape
666 | KeyCode::Find
667 | KeyCode::Help
668 | KeyCode::Pause
669 | KeyCode::Props
670 | KeyCode::Select
671 )
672 }
673
674 /// If the key is for an general device action as defined by [w3].
675 ///
676 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-device
677 pub fn is_device(&self) -> bool {
678 matches!(self, |KeyCode::Eject| KeyCode::Power | KeyCode::PrintScreen | KeyCode::WakeUp)
679 }
680
681 /// If the key is one of the general purpose function keys.
682 pub fn is_function(&self) -> bool {
683 matches!(
684 self,
685 KeyCode::F1
686 | KeyCode::F2
687 | KeyCode::F3
688 | KeyCode::F4
689 | KeyCode::F5
690 | KeyCode::F6
691 | KeyCode::F7
692 | KeyCode::F8
693 | KeyCode::F9
694 | KeyCode::F10
695 | KeyCode::F11
696 | KeyCode::F12
697 | KeyCode::F13
698 | KeyCode::F14
699 | KeyCode::F15
700 | KeyCode::F16
701 | KeyCode::F17
702 | KeyCode::F18
703 | KeyCode::F19
704 | KeyCode::F20
705 | KeyCode::F21
706 | KeyCode::F22
707 | KeyCode::F23
708 | KeyCode::F24
709 | KeyCode::F25
710 | KeyCode::F26
711 | KeyCode::F27
712 | KeyCode::F28
713 | KeyCode::F29
714 | KeyCode::F30
715 | KeyCode::F31
716 | KeyCode::F32
717 | KeyCode::F33
718 | KeyCode::F34
719 | KeyCode::F35
720 )
721 }
722
723 /// If the key is for an multimedia control as defined by [w3].
724 ///
725 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-multimedia
726 pub fn is_multimedia(&self) -> bool {
727 matches!(
728 self,
729 KeyCode::MediaPlayPause | KeyCode::MediaStop | KeyCode::MediaTrackNext | KeyCode::MediaTrackPrevious | KeyCode::Open
730 )
731 }
732
733 /// If the key is for an audio control as defined by [w3].
734 ///
735 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-audio
736 pub fn is_audio(&self) -> bool {
737 matches!(self, KeyCode::AudioVolumeDown | KeyCode::AudioVolumeUp | KeyCode::AudioVolumeMute)
738 }
739
740 /// If the key is for launching an application.
741 pub fn is_launch(&self) -> bool {
742 matches!(self, KeyCode::LaunchMail)
743 }
744
745 /// If the key is for a browser control.
746 pub fn is_browser(&self) -> bool {
747 matches!(
748 self,
749 KeyCode::BrowserBack
750 | KeyCode::BrowserFavorites
751 | KeyCode::BrowserForward
752 | KeyCode::BrowserHome
753 | KeyCode::BrowserRefresh
754 | KeyCode::BrowserSearch
755 | KeyCode::BrowserStop
756 )
757 }
758
759 /// Iterate over all identified values.
760 ///
761 /// The first value is `Backquote` the last is `F35`.
762 pub fn all_identified() -> impl ExactSizeIterator<Item = KeyCode> + DoubleEndedIterator {
763 unsafe {
764 // SAFETY: this is safe because the variants are without associated data.
765 let e: (u16, [u8; 9]) = mem::transmute(KeyCode::F35);
766 (1..=e.0).map(|n| mem::transmute((n, [0u8; 9])))
767 }
768 }
769
770 /// Gets the key as a static str.
771 pub fn name(self) -> &'static str {
772 serde_variant::to_variant_name(&self).unwrap_or("")
773 }
774}
775/// Gets the identified key name or `Unidentified`
776impl std::str::FromStr for KeyCode {
777 type Err = KeyCode;
778
779 fn from_str(s: &str) -> Result<Self, Self::Err> {
780 for v in Self::all_identified() {
781 if v.name() == s {
782 return Ok(v);
783 }
784 }
785 Err(KeyCode::Unidentified(NativeKeyCode::Unidentified))
786 }
787}
788impl fmt::Debug for KeyCode {
789 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
790 if f.alternate() {
791 write!(f, "KeyCode::")?;
792 }
793 let name = self.name();
794 match self {
795 Self::Unidentified(u) => write!(f, "{name}({u:?})"),
796 _ => write!(f, "{name}"),
797 }
798 }
799}
800
801/// Key represents the meaning of a key press.
802///
803/// This mostly conforms to the UI Events Specification's [`KeyboardEvent.key`] with a few
804/// exceptions:
805/// - The `Super` variant here, is named `Meta` in the aforementioned specification. (There's
806/// another key which the specification calls `Super`. That does not exist here.)
807/// - The `Space` variant here, can be identified by the character it generates in the
808/// specification.
809/// - The `Dead` variant here, can specify the character which is inserted when pressing the
810/// dead-key twice.
811///
812/// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/
813#[non_exhaustive]
814#[derive(PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
815#[repr(u16)]
816pub enum Key {
817 /// A key that corresponds to the character typed by the user, taking into account the
818 /// user’s current locale setting, and any system-level keyboard mapping overrides that are in
819 /// effect.
820 Char(char),
821
822 /// A key string that corresponds to the character typed by the user, taking into account the
823 /// user’s current locale setting, and any system-level keyboard mapping overrides that are in
824 /// effect.
825 Str(Txt),
826
827 /// This variant is used when the key cannot be translated to any other variant.
828 ///
829 /// You can try using the [`KeyCode`] to identify the key.
830 Unidentified,
831
832 /// Contains the text representation of the dead-key when available.
833 ///
834 /// ## Platform-specific
835 /// - **Web:** Always contains `None`
836 Dead(Option<char>),
837
838 /* SAFETY, no associated data after Alt, see `Key::all_named` */
839 /// The `Alt` (Alternative) key.
840 ///
841 /// This key enables the alternate modifier function for interpreting concurrent or subsequent
842 /// keyboard input. This key value is also used for the Apple <kbd>Option</kbd> key.
843 Alt = 4,
844 /// The Alternate Graphics (<kbd>AltGr</kbd> or <kbd>AltGraph</kbd>) key.
845 ///
846 /// This key is used enable the ISO Level 3 shift modifier (the standard `Shift` key is the
847 /// level 2 modifier).
848 AltGraph,
849 /// The `Caps Lock` (Capital) key.
850 ///
851 /// Toggle capital character lock function for interpreting subsequent keyboard input event.
852 CapsLock,
853 /// The `Control` or `Ctrl` key.
854 ///
855 /// Used to enable control modifier function for interpreting concurrent or subsequent keyboard
856 /// input.
857 Ctrl,
858 /// The Function switch `Fn` key. Activating this key simultaneously with another key changes
859 /// that key’s value to an alternate character or function. This key is often handled directly
860 /// in the keyboard hardware and does not usually generate key events.
861 Fn,
862 /// The Function-Lock (`FnLock` or `F-Lock`) key. Activating this key switches the mode of the
863 /// keyboard to changes some keys' values to an alternate character or function. This key is
864 /// often handled directly in the keyboard hardware and does not usually generate key events.
865 FnLock,
866 /// The `NumLock` or Number Lock key. Used to toggle numpad mode function for interpreting
867 /// subsequent keyboard input.
868 NumLock,
869 /// Toggle between scrolling and cursor movement modes.
870 ScrollLock,
871 /// Used to enable shift modifier function for interpreting concurrent or subsequent keyboard
872 /// input.
873 Shift,
874 /// The Symbol modifier key (used on some virtual keyboards).
875 Symbol,
876 /// Toggle between normal keyboard and symbols keyboard.
877 SymbolLock,
878 /// Legacy modifier key. Also called "Super" in certain places.
879 Meta,
880 /// Legacy modifier key.
881 Hyper,
882 /// Used to enable "super" modifier function for interpreting concurrent or subsequent keyboard
883 /// input. This key value is used for the "Windows Logo" key and the Apple `Command` or `⌘` key.
884 ///
885 /// Note: In some contexts (e.g. the Web) this is referred to as the "Meta" key.
886 Super,
887 /// The `Enter` or `↵` key. Used to activate current selection or accept current input. This key
888 /// value is also used for the `Return` (Macintosh numpad) key. This key value is also used for
889 /// the Android `KEYCODE_DPAD_CENTER`.
890 Enter,
891 /// The Horizontal Tabulation `Tab` key.
892 Tab,
893 /// Used in text to insert a space between words. Usually located below the character keys.
894 Space,
895 /// Navigate or traverse downward. (`KEYCODE_DPAD_DOWN`)
896 ArrowDown,
897 /// Navigate or traverse leftward. (`KEYCODE_DPAD_LEFT`)
898 ArrowLeft,
899 /// Navigate or traverse rightward. (`KEYCODE_DPAD_RIGHT`)
900 ArrowRight,
901 /// Navigate or traverse upward. (`KEYCODE_DPAD_UP`)
902 ArrowUp,
903 /// The End key, used with keyboard entry to go to the end of content (`KEYCODE_MOVE_END`).
904 End,
905 /// The Home key, used with keyboard entry, to go to start of content (`KEYCODE_MOVE_HOME`).
906 /// For the mobile phone `Home` key (which goes to the phone’s main screen), use [`GoHome`].
907 ///
908 /// [`GoHome`]: Self::GoHome
909 Home,
910 /// Scroll down or display next page of content.
911 PageDown,
912 /// Scroll up or display previous page of content.
913 PageUp,
914 /// Used to remove the character to the left of the cursor. This key value is also used for
915 /// the key labelled `Delete` on MacOS keyboards.
916 Backspace,
917 /// Remove the currently selected input.
918 Clear,
919 /// Copy the current selection. (`APPCOMMAND_COPY`)
920 Copy,
921 /// The Cursor Select key.
922 CrSel,
923 /// Cut the current selection. (`APPCOMMAND_CUT`)
924 Cut,
925 /// Used to delete the character to the right of the cursor. This key value is also used for the
926 /// key labelled `Delete` on MacOS keyboards when `Fn` is active.
927 Delete,
928 /// The Erase to End of Field key. This key deletes all characters from the current cursor
929 /// position to the end of the current field.
930 EraseEof,
931 /// The Extend Selection key.
932 ExSel,
933 /// Toggle between text modes for insertion or overtyping.
934 /// (`KEYCODE_INSERT`)
935 Insert,
936 /// The Paste key. (`APPCOMMAND_PASTE`)
937 Paste,
938 /// Redo the last action. (`APPCOMMAND_REDO`)
939 Redo,
940 /// Undo the last action. (`APPCOMMAND_UNDO`)
941 Undo,
942 /// The Accept (Commit, OK) key. Accept current option or input method sequence conversion.
943 Accept,
944 /// Redo or repeat an action.
945 Again,
946 /// The Attention (Attn) key.
947 Attn,
948 /// Cancel key.
949 Cancel,
950 /// Show the application’s context menu.
951 /// This key is commonly found between the right `Super` key and the right `Ctrl` key.
952 ContextMenu,
953 /// The `Esc` key. This key was originally used to initiate an escape sequence, but is
954 /// now more generally used to exit or "escape" the current context, such as closing a dialog
955 /// or exiting full screen mode.
956 Escape,
957 /// Execute key.
958 Execute,
959 /// Open the Find dialog. (`APPCOMMAND_FIND`)
960 Find,
961 /// Open a help dialog or toggle display of help information. (`APPCOMMAND_HELP`,
962 /// `KEYCODE_HELP`)
963 Help,
964 /// Pause the current state or application (as appropriate).
965 ///
966 /// Note: Do not use this value for the `Pause` button on media controllers. Use `"MediaPause"`
967 /// instead.
968 Pause,
969 /// Play or resume the current state or application (as appropriate).
970 ///
971 /// Note: Do not use this value for the `Play` button on media controllers. Use `"MediaPlay"`
972 /// instead.
973 Play,
974 /// The properties (Props) key.
975 Props,
976 /// Select key.
977 Select,
978 /// The ZoomIn key. (`KEYCODE_ZOOM_IN`)
979 ZoomIn,
980 /// The ZoomOut key. (`KEYCODE_ZOOM_OUT`)
981 ZoomOut,
982 /// The Brightness Down key. Typically controls the display brightness.
983 /// (`KEYCODE_BRIGHTNESS_DOWN`)
984 BrightnessDown,
985 /// The Brightness Up key. Typically controls the display brightness. (`KEYCODE_BRIGHTNESS_UP`)
986 BrightnessUp,
987 /// Toggle removable media to eject (open) and insert (close) state. (`KEYCODE_MEDIA_EJECT`)
988 Eject,
989 /// Log-off key.
990 LogOff,
991 /// Toggle power state. (`KEYCODE_POWER`)
992 /// Note: Note: Some devices might not expose this key to the operating environment.
993 Power,
994 /// The `PowerOff` key. Sometime called `PowerDown`.
995 PowerOff,
996 /// Initiate print-screen function.
997 PrintScreen,
998 /// The Hibernate key. This key saves the current state of the computer to disk so that it can
999 /// be restored. The computer will then shutdown.
1000 Hibernate,
1001 /// The Standby key. This key turns off the display and places the computer into a low-power
1002 /// mode without completely shutting down. It is sometimes labelled `Suspend` or `Sleep` key.
1003 /// (`KEYCODE_SLEEP`)
1004 Standby,
1005 /// The WakeUp key. (`KEYCODE_WAKEUP`)
1006 WakeUp,
1007 /// Initiate the multi-candidate mode.
1008 AllCandidates,
1009 /// Alphanumeric mode.
1010 Alphanumeric,
1011 /// Initiate the Code Input mode to allow characters to be entered by
1012 /// their code points.
1013 CodeInput,
1014 /// The Compose key, also known as "Multi_key" on the X Window System. This key acts in a
1015 /// manner similar to a dead key, triggering a mode where subsequent key presses are combined to
1016 /// produce a different character.
1017 Compose,
1018 /// Convert the current input method sequence.
1019 Convert,
1020 /// The Final Mode `Final` key used on some Asian keyboards, to enable the final mode for IMEs.
1021 FinalMode,
1022 /// Switch to the first character group. (ISO/IEC 9995)
1023 GroupFirst,
1024 /// Switch to the last character group. (ISO/IEC 9995)
1025 GroupLast,
1026 /// Switch to the next character group. (ISO/IEC 9995)
1027 GroupNext,
1028 /// Switch to the previous character group. (ISO/IEC 9995)
1029 GroupPrevious,
1030 /// Toggle between or cycle through input modes of IMEs.
1031 ModeChange,
1032 /// Next IME candidate.
1033 NextCandidate,
1034 /// Accept current input method sequence without
1035 /// conversion in IMEs.
1036 NonConvert,
1037 /// Previous IME candidate.
1038 PreviousCandidate,
1039 /// IME key.
1040 Process,
1041 /// IME key.
1042 SingleCandidate,
1043 /// Toggle between Hangul and English modes.
1044 HangulMode,
1045 /// Toggle between Hanja and English modes.
1046 HanjaMode,
1047 /// Toggle between Junja and English modes.
1048 JunjaMode,
1049 /// The Eisu key. This key may close the IME, but its purpose is defined by the current IME.
1050 /// (`KEYCODE_EISU`)
1051 Eisu,
1052 /// The (Half-Width) Characters key.
1053 Hankaku,
1054 /// The Hiragana (Japanese Kana characters) key.
1055 Hiragana,
1056 /// The Hiragana/Katakana toggle key. (`KEYCODE_KATAKANA_HIRAGANA`)
1057 HiraganaKatakana,
1058 /// The Kana Mode (Kana Lock) key. This key is used to enter hiragana mode (typically from
1059 /// romaji mode).
1060 KanaMode,
1061 /// The Kanji (Japanese name for ideographic characters of Chinese origin) Mode key. This key is
1062 /// typically used to switch to a hiragana keyboard for the purpose of converting input into
1063 /// kanji. (`KEYCODE_KANA`)
1064 KanjiMode,
1065 /// The Katakana (Japanese Kana characters) key.
1066 Katakana,
1067 /// The Roman characters function key.
1068 Romaji,
1069 /// The Zenkaku (Full-Width) Characters key.
1070 Zenkaku,
1071 /// The Zenkaku/Hankaku (full-width/half-width) toggle key. (`KEYCODE_ZENKAKU_HANKAKU`)
1072 ZenkakuHankaku,
1073 /// General purpose virtual function key, as index 1.
1074 Soft1,
1075 /// General purpose virtual function key, as index 2.
1076 Soft2,
1077 /// General purpose virtual function key, as index 3.
1078 Soft3,
1079 /// General purpose virtual function key, as index 4.
1080 Soft4,
1081 /// Select next (numerically or logically) lower channel. (`APPCOMMAND_MEDIA_CHANNEL_DOWN`,
1082 /// `KEYCODE_CHANNEL_DOWN`)
1083 ChannelDown,
1084 /// Select next (numerically or logically) higher channel. (`APPCOMMAND_MEDIA_CHANNEL_UP`,
1085 /// `KEYCODE_CHANNEL_UP`)
1086 ChannelUp,
1087 /// Close the current document or message (Note: This doesn’t close the application).
1088 /// (`APPCOMMAND_CLOSE`)
1089 Close,
1090 /// Open an editor to forward the current message. (`APPCOMMAND_FORWARD_MAIL`)
1091 MailForward,
1092 /// Open an editor to reply to the current message. (`APPCOMMAND_REPLY_TO_MAIL`)
1093 MailReply,
1094 /// Send the current message. (`APPCOMMAND_SEND_MAIL`)
1095 MailSend,
1096 /// Close the current media, for example to close a CD or DVD tray. (`KEYCODE_MEDIA_CLOSE`)
1097 MediaClose,
1098 /// Initiate or continue forward playback at faster than normal speed, or increase speed if
1099 /// already fast forwarding. (`APPCOMMAND_MEDIA_FAST_FORWARD`, `KEYCODE_MEDIA_FAST_FORWARD`)
1100 MediaFastForward,
1101 /// Pause the currently playing media. (`APPCOMMAND_MEDIA_PAUSE`, `KEYCODE_MEDIA_PAUSE`)
1102 ///
1103 /// Note: Media controller devices should use this value rather than `"Pause"` for their pause
1104 /// keys.
1105 MediaPause,
1106 /// Initiate or continue media playback at normal speed, if not currently playing at normal
1107 /// speed. (`APPCOMMAND_MEDIA_PLAY`, `KEYCODE_MEDIA_PLAY`)
1108 MediaPlay,
1109 /// Toggle media between play and pause states. (`APPCOMMAND_MEDIA_PLAY_PAUSE`,
1110 /// `KEYCODE_MEDIA_PLAY_PAUSE`)
1111 MediaPlayPause,
1112 /// Initiate or resume recording of currently selected media. (`APPCOMMAND_MEDIA_RECORD`,
1113 /// `KEYCODE_MEDIA_RECORD`)
1114 MediaRecord,
1115 /// Initiate or continue reverse playback at faster than normal speed, or increase speed if
1116 /// already rewinding. (`APPCOMMAND_MEDIA_REWIND`, `KEYCODE_MEDIA_REWIND`)
1117 MediaRewind,
1118 /// Stop media playing, pausing, forwarding, rewinding, or recording, if not already stopped.
1119 /// (`APPCOMMAND_MEDIA_STOP`, `KEYCODE_MEDIA_STOP`)
1120 MediaStop,
1121 /// Seek to next media or program track. (`APPCOMMAND_MEDIA_NEXTTRACK`, `KEYCODE_MEDIA_NEXT`)
1122 MediaTrackNext,
1123 /// Seek to previous media or program track. (`APPCOMMAND_MEDIA_PREVIOUSTRACK`,
1124 /// `KEYCODE_MEDIA_PREVIOUS`)
1125 MediaTrackPrevious,
1126 /// Open a new document or message. (`APPCOMMAND_NEW`)
1127 New,
1128 /// Open an existing document or message. (`APPCOMMAND_OPEN`)
1129 Open,
1130 /// Print the current document or message. (`APPCOMMAND_PRINT`)
1131 Print,
1132 /// Save the current document or message. (`APPCOMMAND_SAVE`)
1133 Save,
1134 /// Spellcheck the current document or selection. (`APPCOMMAND_SPELL_CHECK`)
1135 SpellCheck,
1136 /// The `11` key found on media numpads that
1137 /// have buttons from `1` ... `12`.
1138 Key11,
1139 /// The `12` key found on media numpads that
1140 /// have buttons from `1` ... `12`.
1141 Key12,
1142 /// Adjust audio balance leftward. (`VK_AUDIO_BALANCE_LEFT`)
1143 AudioBalanceLeft,
1144 /// Adjust audio balance rightward. (`VK_AUDIO_BALANCE_RIGHT`)
1145 AudioBalanceRight,
1146 /// Decrease audio bass boost or cycle down through bass boost states. (`APPCOMMAND_BASS_DOWN`,
1147 /// `VK_BASS_BOOST_DOWN`)
1148 AudioBassBoostDown,
1149 /// Toggle bass boost on/off. (`APPCOMMAND_BASS_BOOST`)
1150 AudioBassBoostToggle,
1151 /// Increase audio bass boost or cycle up through bass boost states. (`APPCOMMAND_BASS_UP`,
1152 /// `VK_BASS_BOOST_UP`)
1153 AudioBassBoostUp,
1154 /// Adjust audio fader towards front. (`VK_FADER_FRONT`)
1155 AudioFaderFront,
1156 /// Adjust audio fader towards rear. (`VK_FADER_REAR`)
1157 AudioFaderRear,
1158 /// Advance surround audio mode to next available mode. (`VK_SURROUND_MODE_NEXT`)
1159 AudioSurroundModeNext,
1160 /// Decrease treble. (`APPCOMMAND_TREBLE_DOWN`)
1161 AudioTrebleDown,
1162 /// Increase treble. (`APPCOMMAND_TREBLE_UP`)
1163 AudioTrebleUp,
1164 /// Decrease audio volume. (`APPCOMMAND_VOLUME_DOWN`, `KEYCODE_VOLUME_DOWN`)
1165 AudioVolumeDown,
1166 /// Increase audio volume. (`APPCOMMAND_VOLUME_UP`, `KEYCODE_VOLUME_UP`)
1167 AudioVolumeUp,
1168 /// Toggle between muted state and prior volume level. (`APPCOMMAND_VOLUME_MUTE`,
1169 /// `KEYCODE_VOLUME_MUTE`)
1170 AudioVolumeMute,
1171 /// Toggle the microphone on/off. (`APPCOMMAND_MIC_ON_OFF_TOGGLE`)
1172 MicrophoneToggle,
1173 /// Decrease microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_DOWN`)
1174 MicrophoneVolumeDown,
1175 /// Increase microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_UP`)
1176 MicrophoneVolumeUp,
1177 /// Mute the microphone. (`APPCOMMAND_MICROPHONE_VOLUME_MUTE`, `KEYCODE_MUTE`)
1178 MicrophoneVolumeMute,
1179 /// Show correction list when a word is incorrectly identified. (`APPCOMMAND_CORRECTION_LIST`)
1180 SpeechCorrectionList,
1181 /// Toggle between dictation mode and command/control mode.
1182 /// (`APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE`)
1183 SpeechInputToggle,
1184 /// The first generic "LaunchApplication" key. This is commonly associated with launching "My
1185 /// Computer", and may have a computer symbol on the key. (`APPCOMMAND_LAUNCH_APP1`)
1186 LaunchApplication1,
1187 /// The second generic "LaunchApplication" key. This is commonly associated with launching
1188 /// "Calculator", and may have a calculator symbol on the key. (`APPCOMMAND_LAUNCH_APP2`,
1189 /// `KEYCODE_CALCULATOR`)
1190 LaunchApplication2,
1191 /// The "Calendar" key. (`KEYCODE_CALENDAR`)
1192 LaunchCalendar,
1193 /// The "Contacts" key. (`KEYCODE_CONTACTS`)
1194 LaunchContacts,
1195 /// The "Mail" key. (`APPCOMMAND_LAUNCH_MAIL`)
1196 LaunchMail,
1197 /// The "Media Player" key. (`APPCOMMAND_LAUNCH_MEDIA_SELECT`)
1198 LaunchMediaPlayer,
1199 /// The "Music Player" key.
1200 LaunchMusicPlayer,
1201 /// The "Phone" key.
1202 LaunchPhone,
1203 /// The "Screen Saver" key.
1204 LaunchScreenSaver,
1205 /// The "Excel" key.
1206 LaunchSpreadsheet,
1207 /// The "Web Browser" key.
1208 LaunchWebBrowser,
1209 /// The "Webcam" key.
1210 LaunchWebCam,
1211 /// The "Word" key.
1212 LaunchWordProcessor,
1213 /// Navigate to previous content or page in current history. (`APPCOMMAND_BROWSER_BACKWARD`)
1214 BrowserBack,
1215 /// Open the list of browser favorites. (`APPCOMMAND_BROWSER_FAVORITES`)
1216 BrowserFavorites,
1217 /// Navigate to next content or page in current history. (`APPCOMMAND_BROWSER_FORWARD`)
1218 BrowserForward,
1219 /// Go to the user’s preferred home page. (`APPCOMMAND_BROWSER_HOME`)
1220 BrowserHome,
1221 /// Refresh the current page or content. (`APPCOMMAND_BROWSER_REFRESH`)
1222 BrowserRefresh,
1223 /// Call up the user’s preferred search page. (`APPCOMMAND_BROWSER_SEARCH`)
1224 BrowserSearch,
1225 /// Stop loading the current page or content. (`APPCOMMAND_BROWSER_STOP`)
1226 BrowserStop,
1227 /// The Application switch key, which provides a list of recent apps to switch between.
1228 /// (`KEYCODE_APP_SWITCH`)
1229 AppSwitch,
1230 /// The Call key. (`KEYCODE_CALL`)
1231 Call,
1232 /// The Camera key. (`KEYCODE_CAMERA`)
1233 Camera,
1234 /// The Camera focus key. (`KEYCODE_FOCUS`)
1235 CameraFocus,
1236 /// The End Call key. (`KEYCODE_ENDCALL`)
1237 EndCall,
1238 /// The Back key. (`KEYCODE_BACK`)
1239 GoBack,
1240 /// The Home key, which goes to the phone’s main screen. (`KEYCODE_HOME`)
1241 GoHome,
1242 /// The Headset Hook key. (`KEYCODE_HEADSETHOOK`)
1243 HeadsetHook,
1244 /// "Last Number Redial" key
1245 LastNumberRedial,
1246 /// The Notification key. (`KEYCODE_NOTIFICATION`)
1247 Notification,
1248 /// Toggle between manner mode state: silent, vibrate, ring, ... (`KEYCODE_MANNER_MODE`)
1249 MannerMode,
1250 /// "Voice Dial" key.
1251 VoiceDial,
1252 /// Switch to viewing TV. (`KEYCODE_TV`)
1253 TV,
1254 /// TV 3D Mode. (`KEYCODE_3D_MODE`)
1255 TV3DMode,
1256 /// Toggle between antenna and cable input. (`KEYCODE_TV_ANTENNA_CABLE`)
1257 TVAntennaCable,
1258 /// Audio description. (`KEYCODE_TV_AUDIO_DESCRIPTION`)
1259 TVAudioDescription,
1260 /// Audio description mixing volume down. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN`)
1261 TVAudioDescriptionMixDown,
1262 /// Audio description mixing volume up. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP`)
1263 TVAudioDescriptionMixUp,
1264 /// Contents menu. (`KEYCODE_TV_CONTENTS_MENU`)
1265 TVContentsMenu,
1266 /// Contents menu. (`KEYCODE_TV_DATA_SERVICE`)
1267 TVDataService,
1268 /// Switch the input mode on an external TV. (`KEYCODE_TV_INPUT`)
1269 TVInput,
1270 /// Switch to component input #1. (`KEYCODE_TV_INPUT_COMPONENT_1`)
1271 TVInputComponent1,
1272 /// Switch to component input #2. (`KEYCODE_TV_INPUT_COMPONENT_2`)
1273 TVInputComponent2,
1274 /// Switch to composite input #1. (`KEYCODE_TV_INPUT_COMPOSITE_1`)
1275 TVInputComposite1,
1276 /// Switch to composite input #2. (`KEYCODE_TV_INPUT_COMPOSITE_2`)
1277 TVInputComposite2,
1278 /// Switch to HDMI input #1. (`KEYCODE_TV_INPUT_HDMI_1`)
1279 TVInputHDMI1,
1280 /// Switch to HDMI input #2. (`KEYCODE_TV_INPUT_HDMI_2`)
1281 TVInputHDMI2,
1282 /// Switch to HDMI input #3. (`KEYCODE_TV_INPUT_HDMI_3`)
1283 TVInputHDMI3,
1284 /// Switch to HDMI input #4. (`KEYCODE_TV_INPUT_HDMI_4`)
1285 TVInputHDMI4,
1286 /// Switch to VGA input #1. (`KEYCODE_TV_INPUT_VGA_1`)
1287 TVInputVGA1,
1288 /// Media context menu. (`KEYCODE_TV_MEDIA_CONTEXT_MENU`)
1289 TVMediaContext,
1290 /// Toggle network. (`KEYCODE_TV_NETWORK`)
1291 TVNetwork,
1292 /// Number entry. (`KEYCODE_TV_NUMBER_ENTRY`)
1293 TVNumberEntry,
1294 /// Toggle the power on an external TV. (`KEYCODE_TV_POWER`)
1295 TVPower,
1296 /// Radio. (`KEYCODE_TV_RADIO_SERVICE`)
1297 TVRadioService,
1298 /// Satellite. (`KEYCODE_TV_SATELLITE`)
1299 TVSatellite,
1300 /// Broadcast Satellite. (`KEYCODE_TV_SATELLITE_BS`)
1301 TVSatelliteBS,
1302 /// Communication Satellite. (`KEYCODE_TV_SATELLITE_CS`)
1303 TVSatelliteCS,
1304 /// Toggle between available satellites. (`KEYCODE_TV_SATELLITE_SERVICE`)
1305 TVSatelliteToggle,
1306 /// Analog Terrestrial. (`KEYCODE_TV_TERRESTRIAL_ANALOG`)
1307 TVTerrestrialAnalog,
1308 /// Digital Terrestrial. (`KEYCODE_TV_TERRESTRIAL_DIGITAL`)
1309 TVTerrestrialDigital,
1310 /// Timer programming. (`KEYCODE_TV_TIMER_PROGRAMMING`)
1311 TVTimer,
1312 /// Switch the input mode on an external AVR (audio/video receiver). (`KEYCODE_AVR_INPUT`)
1313 AVRInput,
1314 /// Toggle the power on an external AVR (audio/video receiver). (`KEYCODE_AVR_POWER`)
1315 AVRPower,
1316 /// General purpose color-coded media function key, as index 0 (red). (`VK_COLORED_KEY_0`,
1317 /// `KEYCODE_PROG_RED`)
1318 ColorF0Red,
1319 /// General purpose color-coded media function key, as index 1 (green). (`VK_COLORED_KEY_1`,
1320 /// `KEYCODE_PROG_GREEN`)
1321 ColorF1Green,
1322 /// General purpose color-coded media function key, as index 2 (yellow). (`VK_COLORED_KEY_2`,
1323 /// `KEYCODE_PROG_YELLOW`)
1324 ColorF2Yellow,
1325 /// General purpose color-coded media function key, as index 3 (blue). (`VK_COLORED_KEY_3`,
1326 /// `KEYCODE_PROG_BLUE`)
1327 ColorF3Blue,
1328 /// General purpose color-coded media function key, as index 4 (grey). (`VK_COLORED_KEY_4`)
1329 ColorF4Grey,
1330 /// General purpose color-coded media function key, as index 5 (brown). (`VK_COLORED_KEY_5`)
1331 ColorF5Brown,
1332 /// Toggle the display of Closed Captions. (`VK_CC`, `KEYCODE_CAPTIONS`)
1333 ClosedCaptionToggle,
1334 /// Adjust brightness of device, by toggling between or cycling through states. (`VK_DIMMER`)
1335 Dimmer,
1336 /// Swap video sources. (`VK_DISPLAY_SWAP`)
1337 DisplaySwap,
1338 /// Select Digital Video Recorder. (`KEYCODE_DVR`)
1339 DVR,
1340 /// Exit the current application. (`VK_EXIT`)
1341 Exit,
1342 /// Clear program or content stored as favorite 0. (`VK_CLEAR_FAVORITE_0`)
1343 FavoriteClear0,
1344 /// Clear program or content stored as favorite 1. (`VK_CLEAR_FAVORITE_1`)
1345 FavoriteClear1,
1346 /// Clear program or content stored as favorite 2. (`VK_CLEAR_FAVORITE_2`)
1347 FavoriteClear2,
1348 /// Clear program or content stored as favorite 3. (`VK_CLEAR_FAVORITE_3`)
1349 FavoriteClear3,
1350 /// Select (recall) program or content stored as favorite 0. (`VK_RECALL_FAVORITE_0`)
1351 FavoriteRecall0,
1352 /// Select (recall) program or content stored as favorite 1. (`VK_RECALL_FAVORITE_1`)
1353 FavoriteRecall1,
1354 /// Select (recall) program or content stored as favorite 2. (`VK_RECALL_FAVORITE_2`)
1355 FavoriteRecall2,
1356 /// Select (recall) program or content stored as favorite 3. (`VK_RECALL_FAVORITE_3`)
1357 FavoriteRecall3,
1358 /// Store current program or content as favorite 0. (`VK_STORE_FAVORITE_0`)
1359 FavoriteStore0,
1360 /// Store current program or content as favorite 1. (`VK_STORE_FAVORITE_1`)
1361 FavoriteStore1,
1362 /// Store current program or content as favorite 2. (`VK_STORE_FAVORITE_2`)
1363 FavoriteStore2,
1364 /// Store current program or content as favorite 3. (`VK_STORE_FAVORITE_3`)
1365 FavoriteStore3,
1366 /// Toggle display of program or content guide. (`VK_GUIDE`, `KEYCODE_GUIDE`)
1367 Guide,
1368 /// If guide is active and displayed, then display next day’s content. (`VK_NEXT_DAY`)
1369 GuideNextDay,
1370 /// If guide is active and displayed, then display previous day’s content. (`VK_PREV_DAY`)
1371 GuidePreviousDay,
1372 /// Toggle display of information about currently selected context or media. (`VK_INFO`,
1373 /// `KEYCODE_INFO`)
1374 Info,
1375 /// Toggle instant replay. (`VK_INSTANT_REPLAY`)
1376 InstantReplay,
1377 /// Launch linked content, if available and appropriate. (`VK_LINK`)
1378 Link,
1379 /// List the current program. (`VK_LIST`)
1380 ListProgram,
1381 /// Toggle display listing of currently available live content or programs. (`VK_LIVE`)
1382 LiveContent,
1383 /// Lock or unlock current content or program. (`VK_LOCK`)
1384 Lock,
1385 /// Show a list of media applications: audio/video players and image viewers. (`VK_APPS`)
1386 ///
1387 /// Note: Do not confuse this key value with the Windows' `VK_APPS` / `VK_CONTEXT_MENU` key,
1388 /// which is encoded as `"ContextMenu"`.
1389 MediaApps,
1390 /// Audio track key. (`KEYCODE_MEDIA_AUDIO_TRACK`)
1391 MediaAudioTrack,
1392 /// Select previously selected channel or media. (`VK_LAST`, `KEYCODE_LAST_CHANNEL`)
1393 MediaLast,
1394 /// Skip backward to next content or program. (`KEYCODE_MEDIA_SKIP_BACKWARD`)
1395 MediaSkipBackward,
1396 /// Skip forward to next content or program. (`VK_SKIP`, `KEYCODE_MEDIA_SKIP_FORWARD`)
1397 MediaSkipForward,
1398 /// Step backward to next content or program. (`KEYCODE_MEDIA_STEP_BACKWARD`)
1399 MediaStepBackward,
1400 /// Step forward to next content or program. (`KEYCODE_MEDIA_STEP_FORWARD`)
1401 MediaStepForward,
1402 /// Media top menu. (`KEYCODE_MEDIA_TOP_MENU`)
1403 MediaTopMenu,
1404 /// Navigate in. (`KEYCODE_NAVIGATE_IN`)
1405 NavigateIn,
1406 /// Navigate to next key. (`KEYCODE_NAVIGATE_NEXT`)
1407 NavigateNext,
1408 /// Navigate out. (`KEYCODE_NAVIGATE_OUT`)
1409 NavigateOut,
1410 /// Navigate to previous key. (`KEYCODE_NAVIGATE_PREVIOUS`)
1411 NavigatePrevious,
1412 /// Cycle to next favorite channel (in favorites list). (`VK_NEXT_FAVORITE_CHANNEL`)
1413 NextFavoriteChannel,
1414 /// Cycle to next user profile (if there are multiple user profiles). (`VK_USER`)
1415 NextUserProfile,
1416 /// Access on-demand content or programs. (`VK_ON_DEMAND`)
1417 OnDemand,
1418 /// Pairing key to pair devices. (`KEYCODE_PAIRING`)
1419 Pairing,
1420 /// Move picture-in-picture window down. (`VK_PINP_DOWN`)
1421 PinPDown,
1422 /// Move picture-in-picture window. (`VK_PINP_MOVE`)
1423 PinPMove,
1424 /// Toggle display of picture-in-picture window. (`VK_PINP_TOGGLE`)
1425 PinPToggle,
1426 /// Move picture-in-picture window up. (`VK_PINP_UP`)
1427 PinPUp,
1428 /// Decrease media playback speed. (`VK_PLAY_SPEED_DOWN`)
1429 PlaySpeedDown,
1430 /// Reset playback to normal speed. (`VK_PLAY_SPEED_RESET`)
1431 PlaySpeedReset,
1432 /// Increase media playback speed. (`VK_PLAY_SPEED_UP`)
1433 PlaySpeedUp,
1434 /// Toggle random media or content shuffle mode. (`VK_RANDOM_TOGGLE`)
1435 RandomToggle,
1436 /// Not a physical key, but this key code is sent when the remote control battery is low.
1437 /// (`VK_RC_LOW_BATTERY`)
1438 RcLowBattery,
1439 /// Toggle or cycle between media recording speeds. (`VK_RECORD_SPEED_NEXT`)
1440 RecordSpeedNext,
1441 /// Toggle RF (radio frequency) input bypass mode (pass RF input directly to the RF output).
1442 /// (`VK_RF_BYPASS`)
1443 RfBypass,
1444 /// Toggle scan channels mode. (`VK_SCAN_CHANNELS_TOGGLE`)
1445 ScanChannelsToggle,
1446 /// Advance display screen mode to next available mode. (`VK_SCREEN_MODE_NEXT`)
1447 ScreenModeNext,
1448 /// Toggle display of device settings screen. (`VK_SETTINGS`, `KEYCODE_SETTINGS`)
1449 Settings,
1450 /// Toggle split screen mode. (`VK_SPLIT_SCREEN_TOGGLE`)
1451 SplitScreenToggle,
1452 /// Switch the input mode on an external STB (set top box). (`KEYCODE_STB_INPUT`)
1453 STBInput,
1454 /// Toggle the power on an external STB (set top box). (`KEYCODE_STB_POWER`)
1455 STBPower,
1456 /// Toggle display of subtitles, if available. (`VK_SUBTITLE`)
1457 Subtitle,
1458 /// Toggle display of teletext, if available (`VK_TELETEXT`, `KEYCODE_TV_TELETEXT`).
1459 Teletext,
1460 /// Advance video mode to next available mode. (`VK_VIDEO_MODE_NEXT`)
1461 VideoModeNext,
1462 /// Cause device to identify itself in some manner, e.g., audibly or visibly. (`VK_WINK`)
1463 Wink,
1464 /// Toggle between fullscreen and scaled content, or alter magnification level. (`VK_ZOOM`,
1465 /// `KEYCODE_TV_ZOOM_MODE`)
1466 ZoomToggle,
1467 /// General-purpose function key.
1468 /// Usually found at the top of the keyboard.
1469 F1,
1470 /// General-purpose function key.
1471 /// Usually found at the top of the keyboard.
1472 F2,
1473 /// General-purpose function key.
1474 /// Usually found at the top of the keyboard.
1475 F3,
1476 /// General-purpose function key.
1477 /// Usually found at the top of the keyboard.
1478 F4,
1479 /// General-purpose function key.
1480 /// Usually found at the top of the keyboard.
1481 F5,
1482 /// General-purpose function key.
1483 /// Usually found at the top of the keyboard.
1484 F6,
1485 /// General-purpose function key.
1486 /// Usually found at the top of the keyboard.
1487 F7,
1488 /// General-purpose function key.
1489 /// Usually found at the top of the keyboard.
1490 F8,
1491 /// General-purpose function key.
1492 /// Usually found at the top of the keyboard.
1493 F9,
1494 /// General-purpose function key.
1495 /// Usually found at the top of the keyboard.
1496 F10,
1497 /// General-purpose function key.
1498 /// Usually found at the top of the keyboard.
1499 F11,
1500 /// General-purpose function key.
1501 /// Usually found at the top of the keyboard.
1502 F12,
1503 /// General-purpose function key.
1504 /// Usually found at the top of the keyboard.
1505 F13,
1506 /// General-purpose function key.
1507 /// Usually found at the top of the keyboard.
1508 F14,
1509 /// General-purpose function key.
1510 /// Usually found at the top of the keyboard.
1511 F15,
1512 /// General-purpose function key.
1513 /// Usually found at the top of the keyboard.
1514 F16,
1515 /// General-purpose function key.
1516 /// Usually found at the top of the keyboard.
1517 F17,
1518 /// General-purpose function key.
1519 /// Usually found at the top of the keyboard.
1520 F18,
1521 /// General-purpose function key.
1522 /// Usually found at the top of the keyboard.
1523 F19,
1524 /// General-purpose function key.
1525 /// Usually found at the top of the keyboard.
1526 F20,
1527 /// General-purpose function key.
1528 /// Usually found at the top of the keyboard.
1529 F21,
1530 /// General-purpose function key.
1531 /// Usually found at the top of the keyboard.
1532 F22,
1533 /// General-purpose function key.
1534 /// Usually found at the top of the keyboard.
1535 F23,
1536 /// General-purpose function key.
1537 /// Usually found at the top of the keyboard.
1538 F24,
1539 /// General-purpose function key.
1540 F25,
1541 /// General-purpose function key.
1542 F26,
1543 /// General-purpose function key.
1544 F27,
1545 /// General-purpose function key.
1546 F28,
1547 /// General-purpose function key.
1548 F29,
1549 /// General-purpose function key.
1550 F30,
1551 /// General-purpose function key.
1552 F31,
1553 /// General-purpose function key.
1554 F32,
1555 /// General-purpose function key.
1556 F33,
1557 /// General-purpose function key.
1558 F34,
1559 /// General-purpose function key.
1560 F35,
1561}
1562impl Clone for Key {
1563 fn clone(&self) -> Self {
1564 key_clone(self)
1565 }
1566}
1567
1568impl Key {
1569 /// If the key is a modifier as defined by [w3].
1570 ///
1571 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-modifier
1572 pub fn is_modifier(&self) -> bool {
1573 matches!(
1574 self,
1575 Key::Ctrl
1576 | Key::Alt
1577 | Key::AltGraph
1578 | Key::CapsLock
1579 | Key::Fn
1580 | Key::FnLock
1581 | Key::Meta
1582 | Key::NumLock
1583 | Key::ScrollLock
1584 | Key::Shift
1585 | Key::Symbol
1586 | Key::SymbolLock
1587 | Key::Super
1588 | Key::Hyper
1589 )
1590 }
1591
1592 /// If the key is a white space as defined by [w3].
1593 ///
1594 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-whitespace
1595 pub fn is_white_space(&self) -> bool {
1596 matches!(self, Key::Tab | Key::Space)
1597 }
1598
1599 /// If the key is for an edit action as defined by [w3].
1600 ///
1601 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-editing
1602 pub fn is_editing(&self) -> bool {
1603 matches!(
1604 self,
1605 Key::Backspace
1606 | Key::Clear
1607 | Key::CrSel
1608 | Key::Cut
1609 | Key::Delete
1610 | Key::EraseEof
1611 | Key::ExSel
1612 | Key::Insert
1613 | Key::Paste
1614 | Key::Redo
1615 | Key::Undo
1616 )
1617 }
1618
1619 /// If the key is for an general UI action as defined by [w3].
1620 ///
1621 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-ui
1622 pub fn is_ui(&self) -> bool {
1623 matches!(
1624 self,
1625 Key::Accept
1626 | Key::Again
1627 | Key::Attn
1628 | Key::Cancel
1629 | Key::ContextMenu
1630 | Key::Escape
1631 | Key::Execute
1632 | Key::Find
1633 | Key::Help
1634 | Key::Pause
1635 | Key::Play
1636 | Key::Props
1637 | Key::Select
1638 | Key::ZoomIn
1639 | Key::ZoomOut
1640 )
1641 }
1642
1643 /// If the key is for an general device action as defined by [w3].
1644 ///
1645 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-device
1646 pub fn is_device(&self) -> bool {
1647 matches!(
1648 self,
1649 Key::BrightnessDown
1650 | Key::BrightnessUp
1651 | Key::Eject
1652 | Key::LogOff
1653 | Key::Power
1654 | Key::PowerOff
1655 | Key::PrintScreen
1656 | Key::Hibernate
1657 | Key::Standby
1658 | Key::WakeUp
1659 )
1660 }
1661
1662 /// If the key if for IME composition actions as defined by [w3].
1663 ///
1664 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-composition
1665 pub fn is_composition(&self) -> bool {
1666 matches!(
1667 self,
1668 Key::AllCandidates
1669 | Key::Alphanumeric
1670 | Key::CodeInput
1671 | Key::Compose
1672 | Key::Convert
1673 | Key::Dead(_)
1674 | Key::FinalMode
1675 | Key::GroupFirst
1676 | Key::GroupLast
1677 | Key::GroupNext
1678 | Key::GroupPrevious
1679 | Key::ModeChange
1680 | Key::NextCandidate
1681 | Key::NonConvert
1682 | Key::PreviousCandidate
1683 | Key::Process
1684 | Key::SingleCandidate
1685 | Key::HangulMode
1686 | Key::HanjaMode
1687 | Key::JunjaMode
1688 | Key::Eisu
1689 | Key::Hankaku
1690 | Key::Hiragana
1691 | Key::HiraganaKatakana
1692 | Key::KanaMode
1693 | Key::KanjiMode
1694 | Key::Katakana
1695 | Key::Romaji
1696 | Key::Zenkaku
1697 | Key::ZenkakuHankaku
1698 )
1699 }
1700
1701 /// If the key is one of the general purpose function keys.
1702 pub fn is_function(&self) -> bool {
1703 matches!(
1704 self,
1705 Key::F1
1706 | Key::F2
1707 | Key::F3
1708 | Key::F4
1709 | Key::F5
1710 | Key::F6
1711 | Key::F7
1712 | Key::F8
1713 | Key::F9
1714 | Key::F10
1715 | Key::F11
1716 | Key::F12
1717 | Key::F13
1718 | Key::F14
1719 | Key::F15
1720 | Key::F16
1721 | Key::F17
1722 | Key::F18
1723 | Key::F19
1724 | Key::F20
1725 | Key::F21
1726 | Key::F22
1727 | Key::F23
1728 | Key::F24
1729 | Key::F25
1730 | Key::F26
1731 | Key::F27
1732 | Key::F28
1733 | Key::F29
1734 | Key::F30
1735 | Key::F31
1736 | Key::F32
1737 | Key::F33
1738 | Key::F34
1739 | Key::F35
1740 | Key::Soft1
1741 | Key::Soft2
1742 | Key::Soft3
1743 | Key::Soft4
1744 )
1745 }
1746
1747 /// If the key is for an multimedia control as defined by [w3].
1748 ///
1749 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-multimedia
1750 pub fn is_multimedia(&self) -> bool {
1751 matches!(
1752 self,
1753 Key::ChannelDown
1754 | Key::ChannelUp
1755 | Key::Close
1756 | Key::MailForward
1757 | Key::MailReply
1758 | Key::MailSend
1759 | Key::MediaClose
1760 | Key::MediaFastForward
1761 | Key::MediaPause
1762 | Key::MediaPlay
1763 | Key::MediaPlayPause
1764 | Key::MediaRecord
1765 | Key::MediaRewind
1766 | Key::MediaStop
1767 | Key::MediaTrackNext
1768 | Key::MediaTrackPrevious
1769 | Key::New
1770 | Key::Open
1771 | Key::Print
1772 | Key::Save
1773 | Key::SpellCheck
1774 )
1775 }
1776
1777 /// If the key is for an audio control as defined by [w3].
1778 ///
1779 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-audio
1780 pub fn is_audio(&self) -> bool {
1781 matches!(
1782 self,
1783 Key::AudioBalanceLeft
1784 | Key::AudioBalanceRight
1785 | Key::AudioBassBoostDown
1786 | Key::AudioBassBoostToggle
1787 | Key::AudioBassBoostUp
1788 | Key::AudioFaderFront
1789 | Key::AudioFaderRear
1790 | Key::AudioSurroundModeNext
1791 | Key::AudioTrebleDown
1792 | Key::AudioTrebleUp
1793 | Key::AudioVolumeDown
1794 | Key::AudioVolumeUp
1795 | Key::AudioVolumeMute
1796 | Key::MicrophoneToggle
1797 | Key::MicrophoneVolumeDown
1798 | Key::MicrophoneVolumeUp
1799 | Key::MicrophoneVolumeMute
1800 )
1801 }
1802
1803 /// If the key is for a speech correction control as defined by [w3].
1804 ///
1805 /// [w3]:https://www.w3.org/TR/uievents-key/#keys-speech
1806 pub fn is_speech(&self) -> bool {
1807 matches!(self, Key::SpeechCorrectionList | Key::SpeechInputToggle)
1808 }
1809
1810 /// If the key is for launching an application.
1811 pub fn is_launch(&self) -> bool {
1812 matches!(
1813 self,
1814 Key::LaunchApplication1
1815 | Key::LaunchApplication2
1816 | Key::LaunchCalendar
1817 | Key::LaunchContacts
1818 | Key::LaunchMail
1819 | Key::LaunchMediaPlayer
1820 | Key::LaunchMusicPlayer
1821 | Key::LaunchPhone
1822 | Key::LaunchScreenSaver
1823 | Key::LaunchSpreadsheet
1824 | Key::LaunchWebBrowser
1825 | Key::LaunchWebCam
1826 | Key::LaunchWordProcessor
1827 )
1828 }
1829
1830 /// If the key is for a browser control.
1831 pub fn is_browser(&self) -> bool {
1832 matches!(
1833 self,
1834 Key::BrowserBack
1835 | Key::BrowserFavorites
1836 | Key::BrowserForward
1837 | Key::BrowserHome
1838 | Key::BrowserRefresh
1839 | Key::BrowserSearch
1840 | Key::BrowserStop
1841 )
1842 }
1843
1844 /// If the key is from a mobile phone as defined by [w3].
1845 ///
1846 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-mobile
1847 pub fn is_mobile(&self) -> bool {
1848 matches!(
1849 self,
1850 Key::AppSwitch
1851 | Key::Call
1852 | Key::Camera
1853 | Key::CameraFocus
1854 | Key::EndCall
1855 | Key::GoBack
1856 | Key::GoHome
1857 | Key::HeadsetHook
1858 | Key::LastNumberRedial
1859 | Key::Notification
1860 | Key::MannerMode
1861 | Key::VoiceDial
1862 )
1863 }
1864
1865 /// If the key is from a TV control as defined by [w3].
1866 ///
1867 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-tv
1868 pub fn is_tv(&self) -> bool {
1869 matches!(
1870 self,
1871 Key::TV
1872 | Key::TV3DMode
1873 | Key::TVAntennaCable
1874 | Key::TVAudioDescription
1875 | Key::TVAudioDescriptionMixDown
1876 | Key::TVAudioDescriptionMixUp
1877 | Key::TVContentsMenu
1878 | Key::TVDataService
1879 | Key::TVInput
1880 | Key::TVInputComponent1
1881 | Key::TVInputComponent2
1882 | Key::TVInputComposite1
1883 | Key::TVInputComposite2
1884 | Key::TVInputHDMI1
1885 | Key::TVInputHDMI2
1886 | Key::TVInputHDMI3
1887 | Key::TVInputHDMI4
1888 | Key::TVInputVGA1
1889 | Key::TVMediaContext
1890 | Key::TVNetwork
1891 | Key::TVNumberEntry
1892 | Key::TVPower
1893 | Key::TVRadioService
1894 | Key::TVSatellite
1895 | Key::TVSatelliteBS
1896 | Key::TVSatelliteCS
1897 | Key::TVSatelliteToggle
1898 | Key::TVTerrestrialAnalog
1899 | Key::TVTerrestrialDigital
1900 | Key::TVTimer
1901 )
1902 }
1903
1904 /// If the key is for a media controller as defined by [w3].
1905 ///
1906 /// [w3]: https://www.w3.org/TR/uievents-key/#keys-media-controller
1907 pub fn is_media_controller(&self) -> bool {
1908 matches!(
1909 self,
1910 Key::AVRInput
1911 | Key::AVRPower
1912 | Key::ColorF0Red
1913 | Key::ColorF1Green
1914 | Key::ColorF2Yellow
1915 | Key::ColorF3Blue
1916 | Key::ColorF4Grey
1917 | Key::ColorF5Brown
1918 | Key::ClosedCaptionToggle
1919 | Key::Dimmer
1920 | Key::DisplaySwap
1921 | Key::DVR
1922 | Key::Exit
1923 | Key::FavoriteClear0
1924 | Key::FavoriteClear1
1925 | Key::FavoriteClear2
1926 | Key::FavoriteClear3
1927 | Key::FavoriteRecall0
1928 | Key::FavoriteRecall1
1929 | Key::FavoriteRecall2
1930 | Key::FavoriteRecall3
1931 | Key::FavoriteStore0
1932 | Key::FavoriteStore1
1933 | Key::FavoriteStore2
1934 | Key::FavoriteStore3
1935 | Key::Guide
1936 | Key::GuideNextDay
1937 | Key::GuidePreviousDay
1938 | Key::Info
1939 | Key::InstantReplay
1940 | Key::Link
1941 | Key::ListProgram
1942 | Key::LiveContent
1943 | Key::Lock
1944 | Key::MediaApps
1945 | Key::MediaAudioTrack
1946 | Key::MediaLast
1947 | Key::MediaSkipBackward
1948 | Key::MediaSkipForward
1949 | Key::MediaStepBackward
1950 | Key::MediaStepForward
1951 | Key::MediaTopMenu
1952 | Key::NavigateIn
1953 | Key::NavigateNext
1954 | Key::NavigateOut
1955 | Key::NavigatePrevious
1956 | Key::NextFavoriteChannel
1957 | Key::NextUserProfile
1958 | Key::OnDemand
1959 | Key::Pairing
1960 | Key::PinPDown
1961 | Key::PinPMove
1962 | Key::PinPToggle
1963 | Key::PinPUp
1964 | Key::PlaySpeedDown
1965 | Key::PlaySpeedReset
1966 | Key::PlaySpeedUp
1967 | Key::RandomToggle
1968 | Key::RcLowBattery
1969 | Key::RecordSpeedNext
1970 | Key::RfBypass
1971 | Key::ScanChannelsToggle
1972 | Key::ScreenModeNext
1973 | Key::Settings
1974 | Key::SplitScreenToggle
1975 | Key::STBInput
1976 | Key::STBPower
1977 | Key::Subtitle
1978 | Key::Teletext
1979 | Key::VideoModeNext
1980 | Key::Wink
1981 | Key::ZoomToggle
1982 )
1983 }
1984
1985 /// Gets the variant name.
1986 pub fn name(&self) -> &'static str {
1987 serde_variant::to_variant_name(self).unwrap_or("")
1988 }
1989
1990 /// Gets the named key, or `Char` or `Str`.
1991 #[expect(clippy::should_implement_trait)]
1992 pub fn from_str(s: &str) -> Self {
1993 let mut n = s.chars();
1994 if let Some(c) = n.next()
1995 && n.next().is_none()
1996 {
1997 return Self::Char(c);
1998 }
1999
2000 for v in Self::all_named() {
2001 if v.name() == s {
2002 return v;
2003 }
2004 }
2005
2006 Self::Str(s.to_owned().into())
2007 }
2008
2009 /// Iterate over all values from `Alt` to `F35`.
2010 pub fn all_named() -> impl ExactSizeIterator<Item = Key> + DoubleEndedIterator {
2011 unsafe {
2012 // SAFETY: this is safe because all variants from `Alt` are without associated data and Key is `repr(u16)`.
2013 const KEY_DATA_SIZE: usize = mem::size_of::<Key>() - mem::size_of::<u16>();
2014 let s: (u16, [u8; KEY_DATA_SIZE]) = mem::transmute(Key::Alt);
2015 let e: (u16, [u8; KEY_DATA_SIZE]) = mem::transmute(Key::F35);
2016 (s.0..=e.0).map(|n| mem::transmute((n, [0u8; KEY_DATA_SIZE])))
2017 }
2018 }
2019}
2020impl std::str::FromStr for Key {
2021 type Err = ();
2022
2023 fn from_str(s: &str) -> Result<Self, Self::Err> {
2024 Ok(Self::from_str(s))
2025 }
2026}
2027impl fmt::Debug for Key {
2028 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
2029 if f.alternate() {
2030 write!(f, "Key::")?;
2031 }
2032 let name = self.name();
2033 match self {
2034 Self::Char(c) => write!(f, "{name}({c:?})"),
2035 Self::Str(s) => write!(f, "{name}({:?})", s.as_str()),
2036 Self::Dead(c) => write!(f, "{name}({c:?})"),
2037 _ => write!(f, "{name}"),
2038 }
2039 }
2040}
2041
2042/// State a [`Key`] has entered.
2043#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
2044pub enum KeyState {
2045 /// The key was pressed.
2046 Pressed,
2047 /// The key was released.
2048 Released,
2049}
2050
2051// monomorphize
2052fn key_clone(key: &Key) -> Key {
2053 match key {
2054 Key::Char(arg0) => Key::Char(*arg0),
2055 Key::Str(arg0) => Key::Str(arg0.clone()),
2056 Key::Unidentified => Key::Unidentified,
2057 Key::Dead(arg0) => Key::Dead(*arg0),
2058 Key::Alt => Key::Alt,
2059 Key::AltGraph => Key::AltGraph,
2060 Key::CapsLock => Key::CapsLock,
2061 Key::Ctrl => Key::Ctrl,
2062 Key::Fn => Key::Fn,
2063 Key::FnLock => Key::FnLock,
2064 Key::NumLock => Key::NumLock,
2065 Key::ScrollLock => Key::ScrollLock,
2066 Key::Shift => Key::Shift,
2067 Key::Symbol => Key::Symbol,
2068 Key::SymbolLock => Key::SymbolLock,
2069 Key::Meta => Key::Meta,
2070 Key::Hyper => Key::Hyper,
2071 Key::Super => Key::Super,
2072 Key::Enter => Key::Enter,
2073 Key::Tab => Key::Tab,
2074 Key::Space => Key::Space,
2075 Key::ArrowDown => Key::ArrowDown,
2076 Key::ArrowLeft => Key::ArrowLeft,
2077 Key::ArrowRight => Key::ArrowRight,
2078 Key::ArrowUp => Key::ArrowUp,
2079 Key::End => Key::End,
2080 Key::Home => Key::Home,
2081 Key::PageDown => Key::PageDown,
2082 Key::PageUp => Key::PageUp,
2083 Key::Backspace => Key::Backspace,
2084 Key::Clear => Key::Clear,
2085 Key::Copy => Key::Copy,
2086 Key::CrSel => Key::CrSel,
2087 Key::Cut => Key::Cut,
2088 Key::Delete => Key::Delete,
2089 Key::EraseEof => Key::EraseEof,
2090 Key::ExSel => Key::ExSel,
2091 Key::Insert => Key::Insert,
2092 Key::Paste => Key::Paste,
2093 Key::Redo => Key::Redo,
2094 Key::Undo => Key::Undo,
2095 Key::Accept => Key::Accept,
2096 Key::Again => Key::Again,
2097 Key::Attn => Key::Attn,
2098 Key::Cancel => Key::Cancel,
2099 Key::ContextMenu => Key::ContextMenu,
2100 Key::Escape => Key::Escape,
2101 Key::Execute => Key::Execute,
2102 Key::Find => Key::Find,
2103 Key::Help => Key::Help,
2104 Key::Pause => Key::Pause,
2105 Key::Play => Key::Play,
2106 Key::Props => Key::Props,
2107 Key::Select => Key::Select,
2108 Key::ZoomIn => Key::ZoomIn,
2109 Key::ZoomOut => Key::ZoomOut,
2110 Key::BrightnessDown => Key::BrightnessDown,
2111 Key::BrightnessUp => Key::BrightnessUp,
2112 Key::Eject => Key::Eject,
2113 Key::LogOff => Key::LogOff,
2114 Key::Power => Key::Power,
2115 Key::PowerOff => Key::PowerOff,
2116 Key::PrintScreen => Key::PrintScreen,
2117 Key::Hibernate => Key::Hibernate,
2118 Key::Standby => Key::Standby,
2119 Key::WakeUp => Key::WakeUp,
2120 Key::AllCandidates => Key::AllCandidates,
2121 Key::Alphanumeric => Key::Alphanumeric,
2122 Key::CodeInput => Key::CodeInput,
2123 Key::Compose => Key::Compose,
2124 Key::Convert => Key::Convert,
2125 Key::FinalMode => Key::FinalMode,
2126 Key::GroupFirst => Key::GroupFirst,
2127 Key::GroupLast => Key::GroupLast,
2128 Key::GroupNext => Key::GroupNext,
2129 Key::GroupPrevious => Key::GroupPrevious,
2130 Key::ModeChange => Key::ModeChange,
2131 Key::NextCandidate => Key::NextCandidate,
2132 Key::NonConvert => Key::NonConvert,
2133 Key::PreviousCandidate => Key::PreviousCandidate,
2134 Key::Process => Key::Process,
2135 Key::SingleCandidate => Key::SingleCandidate,
2136 Key::HangulMode => Key::HangulMode,
2137 Key::HanjaMode => Key::HanjaMode,
2138 Key::JunjaMode => Key::JunjaMode,
2139 Key::Eisu => Key::Eisu,
2140 Key::Hankaku => Key::Hankaku,
2141 Key::Hiragana => Key::Hiragana,
2142 Key::HiraganaKatakana => Key::HiraganaKatakana,
2143 Key::KanaMode => Key::KanaMode,
2144 Key::KanjiMode => Key::KanjiMode,
2145 Key::Katakana => Key::Katakana,
2146 Key::Romaji => Key::Romaji,
2147 Key::Zenkaku => Key::Zenkaku,
2148 Key::ZenkakuHankaku => Key::ZenkakuHankaku,
2149 Key::Soft1 => Key::Soft1,
2150 Key::Soft2 => Key::Soft2,
2151 Key::Soft3 => Key::Soft3,
2152 Key::Soft4 => Key::Soft4,
2153 Key::ChannelDown => Key::ChannelDown,
2154 Key::ChannelUp => Key::ChannelUp,
2155 Key::Close => Key::Close,
2156 Key::MailForward => Key::MailForward,
2157 Key::MailReply => Key::MailReply,
2158 Key::MailSend => Key::MailSend,
2159 Key::MediaClose => Key::MediaClose,
2160 Key::MediaFastForward => Key::MediaFastForward,
2161 Key::MediaPause => Key::MediaPause,
2162 Key::MediaPlay => Key::MediaPlay,
2163 Key::MediaPlayPause => Key::MediaPlayPause,
2164 Key::MediaRecord => Key::MediaRecord,
2165 Key::MediaRewind => Key::MediaRewind,
2166 Key::MediaStop => Key::MediaStop,
2167 Key::MediaTrackNext => Key::MediaTrackNext,
2168 Key::MediaTrackPrevious => Key::MediaTrackPrevious,
2169 Key::New => Key::New,
2170 Key::Open => Key::Open,
2171 Key::Print => Key::Print,
2172 Key::Save => Key::Save,
2173 Key::SpellCheck => Key::SpellCheck,
2174 Key::Key11 => Key::Key11,
2175 Key::Key12 => Key::Key12,
2176 Key::AudioBalanceLeft => Key::AudioBalanceLeft,
2177 Key::AudioBalanceRight => Key::AudioBalanceRight,
2178 Key::AudioBassBoostDown => Key::AudioBassBoostDown,
2179 Key::AudioBassBoostToggle => Key::AudioBassBoostToggle,
2180 Key::AudioBassBoostUp => Key::AudioBassBoostUp,
2181 Key::AudioFaderFront => Key::AudioFaderFront,
2182 Key::AudioFaderRear => Key::AudioFaderRear,
2183 Key::AudioSurroundModeNext => Key::AudioSurroundModeNext,
2184 Key::AudioTrebleDown => Key::AudioTrebleDown,
2185 Key::AudioTrebleUp => Key::AudioTrebleUp,
2186 Key::AudioVolumeDown => Key::AudioVolumeDown,
2187 Key::AudioVolumeUp => Key::AudioVolumeUp,
2188 Key::AudioVolumeMute => Key::AudioVolumeMute,
2189 Key::MicrophoneToggle => Key::MicrophoneToggle,
2190 Key::MicrophoneVolumeDown => Key::MicrophoneVolumeDown,
2191 Key::MicrophoneVolumeUp => Key::MicrophoneVolumeUp,
2192 Key::MicrophoneVolumeMute => Key::MicrophoneVolumeMute,
2193 Key::SpeechCorrectionList => Key::SpeechCorrectionList,
2194 Key::SpeechInputToggle => Key::SpeechInputToggle,
2195 Key::LaunchApplication1 => Key::LaunchApplication1,
2196 Key::LaunchApplication2 => Key::LaunchApplication2,
2197 Key::LaunchCalendar => Key::LaunchCalendar,
2198 Key::LaunchContacts => Key::LaunchContacts,
2199 Key::LaunchMail => Key::LaunchMail,
2200 Key::LaunchMediaPlayer => Key::LaunchMediaPlayer,
2201 Key::LaunchMusicPlayer => Key::LaunchMusicPlayer,
2202 Key::LaunchPhone => Key::LaunchPhone,
2203 Key::LaunchScreenSaver => Key::LaunchScreenSaver,
2204 Key::LaunchSpreadsheet => Key::LaunchSpreadsheet,
2205 Key::LaunchWebBrowser => Key::LaunchWebBrowser,
2206 Key::LaunchWebCam => Key::LaunchWebCam,
2207 Key::LaunchWordProcessor => Key::LaunchWordProcessor,
2208 Key::BrowserBack => Key::BrowserBack,
2209 Key::BrowserFavorites => Key::BrowserFavorites,
2210 Key::BrowserForward => Key::BrowserForward,
2211 Key::BrowserHome => Key::BrowserHome,
2212 Key::BrowserRefresh => Key::BrowserRefresh,
2213 Key::BrowserSearch => Key::BrowserSearch,
2214 Key::BrowserStop => Key::BrowserStop,
2215 Key::AppSwitch => Key::AppSwitch,
2216 Key::Call => Key::Call,
2217 Key::Camera => Key::Camera,
2218 Key::CameraFocus => Key::CameraFocus,
2219 Key::EndCall => Key::EndCall,
2220 Key::GoBack => Key::GoBack,
2221 Key::GoHome => Key::GoHome,
2222 Key::HeadsetHook => Key::HeadsetHook,
2223 Key::LastNumberRedial => Key::LastNumberRedial,
2224 Key::Notification => Key::Notification,
2225 Key::MannerMode => Key::MannerMode,
2226 Key::VoiceDial => Key::VoiceDial,
2227 Key::TV => Key::TV,
2228 Key::TV3DMode => Key::TV3DMode,
2229 Key::TVAntennaCable => Key::TVAntennaCable,
2230 Key::TVAudioDescription => Key::TVAudioDescription,
2231 Key::TVAudioDescriptionMixDown => Key::TVAudioDescriptionMixDown,
2232 Key::TVAudioDescriptionMixUp => Key::TVAudioDescriptionMixUp,
2233 Key::TVContentsMenu => Key::TVContentsMenu,
2234 Key::TVDataService => Key::TVDataService,
2235 Key::TVInput => Key::TVInput,
2236 Key::TVInputComponent1 => Key::TVInputComponent1,
2237 Key::TVInputComponent2 => Key::TVInputComponent2,
2238 Key::TVInputComposite1 => Key::TVInputComposite1,
2239 Key::TVInputComposite2 => Key::TVInputComposite2,
2240 Key::TVInputHDMI1 => Key::TVInputHDMI1,
2241 Key::TVInputHDMI2 => Key::TVInputHDMI2,
2242 Key::TVInputHDMI3 => Key::TVInputHDMI3,
2243 Key::TVInputHDMI4 => Key::TVInputHDMI4,
2244 Key::TVInputVGA1 => Key::TVInputVGA1,
2245 Key::TVMediaContext => Key::TVMediaContext,
2246 Key::TVNetwork => Key::TVNetwork,
2247 Key::TVNumberEntry => Key::TVNumberEntry,
2248 Key::TVPower => Key::TVPower,
2249 Key::TVRadioService => Key::TVRadioService,
2250 Key::TVSatellite => Key::TVSatellite,
2251 Key::TVSatelliteBS => Key::TVSatelliteBS,
2252 Key::TVSatelliteCS => Key::TVSatelliteCS,
2253 Key::TVSatelliteToggle => Key::TVSatelliteToggle,
2254 Key::TVTerrestrialAnalog => Key::TVTerrestrialAnalog,
2255 Key::TVTerrestrialDigital => Key::TVTerrestrialDigital,
2256 Key::TVTimer => Key::TVTimer,
2257 Key::AVRInput => Key::AVRInput,
2258 Key::AVRPower => Key::AVRPower,
2259 Key::ColorF0Red => Key::ColorF0Red,
2260 Key::ColorF1Green => Key::ColorF1Green,
2261 Key::ColorF2Yellow => Key::ColorF2Yellow,
2262 Key::ColorF3Blue => Key::ColorF3Blue,
2263 Key::ColorF4Grey => Key::ColorF4Grey,
2264 Key::ColorF5Brown => Key::ColorF5Brown,
2265 Key::ClosedCaptionToggle => Key::ClosedCaptionToggle,
2266 Key::Dimmer => Key::Dimmer,
2267 Key::DisplaySwap => Key::DisplaySwap,
2268 Key::DVR => Key::DVR,
2269 Key::Exit => Key::Exit,
2270 Key::FavoriteClear0 => Key::FavoriteClear0,
2271 Key::FavoriteClear1 => Key::FavoriteClear1,
2272 Key::FavoriteClear2 => Key::FavoriteClear2,
2273 Key::FavoriteClear3 => Key::FavoriteClear3,
2274 Key::FavoriteRecall0 => Key::FavoriteRecall0,
2275 Key::FavoriteRecall1 => Key::FavoriteRecall1,
2276 Key::FavoriteRecall2 => Key::FavoriteRecall2,
2277 Key::FavoriteRecall3 => Key::FavoriteRecall3,
2278 Key::FavoriteStore0 => Key::FavoriteStore0,
2279 Key::FavoriteStore1 => Key::FavoriteStore1,
2280 Key::FavoriteStore2 => Key::FavoriteStore2,
2281 Key::FavoriteStore3 => Key::FavoriteStore3,
2282 Key::Guide => Key::Guide,
2283 Key::GuideNextDay => Key::GuideNextDay,
2284 Key::GuidePreviousDay => Key::GuidePreviousDay,
2285 Key::Info => Key::Info,
2286 Key::InstantReplay => Key::InstantReplay,
2287 Key::Link => Key::Link,
2288 Key::ListProgram => Key::ListProgram,
2289 Key::LiveContent => Key::LiveContent,
2290 Key::Lock => Key::Lock,
2291 Key::MediaApps => Key::MediaApps,
2292 Key::MediaAudioTrack => Key::MediaAudioTrack,
2293 Key::MediaLast => Key::MediaLast,
2294 Key::MediaSkipBackward => Key::MediaSkipBackward,
2295 Key::MediaSkipForward => Key::MediaSkipForward,
2296 Key::MediaStepBackward => Key::MediaStepBackward,
2297 Key::MediaStepForward => Key::MediaStepForward,
2298 Key::MediaTopMenu => Key::MediaTopMenu,
2299 Key::NavigateIn => Key::NavigateIn,
2300 Key::NavigateNext => Key::NavigateNext,
2301 Key::NavigateOut => Key::NavigateOut,
2302 Key::NavigatePrevious => Key::NavigatePrevious,
2303 Key::NextFavoriteChannel => Key::NextFavoriteChannel,
2304 Key::NextUserProfile => Key::NextUserProfile,
2305 Key::OnDemand => Key::OnDemand,
2306 Key::Pairing => Key::Pairing,
2307 Key::PinPDown => Key::PinPDown,
2308 Key::PinPMove => Key::PinPMove,
2309 Key::PinPToggle => Key::PinPToggle,
2310 Key::PinPUp => Key::PinPUp,
2311 Key::PlaySpeedDown => Key::PlaySpeedDown,
2312 Key::PlaySpeedReset => Key::PlaySpeedReset,
2313 Key::PlaySpeedUp => Key::PlaySpeedUp,
2314 Key::RandomToggle => Key::RandomToggle,
2315 Key::RcLowBattery => Key::RcLowBattery,
2316 Key::RecordSpeedNext => Key::RecordSpeedNext,
2317 Key::RfBypass => Key::RfBypass,
2318 Key::ScanChannelsToggle => Key::ScanChannelsToggle,
2319 Key::ScreenModeNext => Key::ScreenModeNext,
2320 Key::Settings => Key::Settings,
2321 Key::SplitScreenToggle => Key::SplitScreenToggle,
2322 Key::STBInput => Key::STBInput,
2323 Key::STBPower => Key::STBPower,
2324 Key::Subtitle => Key::Subtitle,
2325 Key::Teletext => Key::Teletext,
2326 Key::VideoModeNext => Key::VideoModeNext,
2327 Key::Wink => Key::Wink,
2328 Key::ZoomToggle => Key::ZoomToggle,
2329 Key::F1 => Key::F1,
2330 Key::F2 => Key::F2,
2331 Key::F3 => Key::F3,
2332 Key::F4 => Key::F4,
2333 Key::F5 => Key::F5,
2334 Key::F6 => Key::F6,
2335 Key::F7 => Key::F7,
2336 Key::F8 => Key::F8,
2337 Key::F9 => Key::F9,
2338 Key::F10 => Key::F10,
2339 Key::F11 => Key::F11,
2340 Key::F12 => Key::F12,
2341 Key::F13 => Key::F13,
2342 Key::F14 => Key::F14,
2343 Key::F15 => Key::F15,
2344 Key::F16 => Key::F16,
2345 Key::F17 => Key::F17,
2346 Key::F18 => Key::F18,
2347 Key::F19 => Key::F19,
2348 Key::F20 => Key::F20,
2349 Key::F21 => Key::F21,
2350 Key::F22 => Key::F22,
2351 Key::F23 => Key::F23,
2352 Key::F24 => Key::F24,
2353 Key::F25 => Key::F25,
2354 Key::F26 => Key::F26,
2355 Key::F27 => Key::F27,
2356 Key::F28 => Key::F28,
2357 Key::F29 => Key::F29,
2358 Key::F30 => Key::F30,
2359 Key::F31 => Key::F31,
2360 Key::F32 => Key::F32,
2361 Key::F33 => Key::F33,
2362 Key::F34 => Key::F34,
2363 Key::F35 => Key::F35,
2364 }
2365}