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