iced_core/keyboard/
key.rs

1//! Identify keyboard keys.
2use crate::SmolStr;
3
4/// A key on the keyboard.
5///
6/// This is mostly the `Key` type found in [`winit`].
7///
8/// [`winit`]: https://docs.rs/winit/0.29.10/winit/keyboard/enum.Key.html
9#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub enum Key<C = SmolStr> {
11    /// A key with an established name.
12    Named(Named),
13
14    /// A key string that corresponds to the character typed by the user, taking into account the
15    /// user’s current locale setting, and any system-level keyboard mapping overrides that are in
16    /// effect.
17    Character(C),
18
19    /// An unidentified key.
20    Unidentified,
21}
22
23impl Key {
24    /// Convert `Key::Character(SmolStr)` to `Key::Character(&str)` so you can more easily match on
25    /// `Key`. All other variants remain unchanged.
26    pub fn as_ref(&self) -> Key<&str> {
27        match self {
28            Self::Named(named) => Key::Named(*named),
29            Self::Character(c) => Key::Character(c.as_ref()),
30            Self::Unidentified => Key::Unidentified,
31        }
32    }
33
34    /// Tries to convert this logical [`Key`] into its latin character, using the
35    /// [`Physical`] key provided for translation if it isn't already in latin.
36    ///
37    /// Returns `None` if no latin variant could be found.
38    ///
39    /// ```
40    /// use iced_core::keyboard::key::{Key, Named, Physical, Code};
41    ///
42    /// // Latin c
43    /// assert_eq!(
44    ///     Key::Character("c".into()).to_latin(Physical::Code(Code::KeyC)),
45    ///     Some('c'),
46    /// );
47    ///
48    /// // Cyrillic с
49    /// assert_eq!(
50    ///     Key::Character("с".into()).to_latin(Physical::Code(Code::KeyC)),
51    ///     Some('c'),
52    /// );
53    ///
54    /// // Arrow Left
55    /// assert_eq!(
56    ///     Key::Named(Named::ArrowLeft).to_latin(Physical::Code(Code::ArrowLeft)),
57    ///     None,
58    /// );
59    /// ```
60    pub fn to_latin(&self, physical_key: Physical) -> Option<char> {
61        let Self::Character(s) = self else {
62            return None;
63        };
64
65        let mut chars = s.chars();
66        let c = chars.next()?;
67
68        if chars.next().is_none() && c < '\u{370}' {
69            return Some(c);
70        }
71
72        let Physical::Code(code) = physical_key else {
73            return None;
74        };
75
76        let latin = match code {
77            Code::KeyA => 'a',
78            Code::KeyB => 'b',
79            Code::KeyC => 'c',
80            Code::KeyD => 'd',
81            Code::KeyE => 'e',
82            Code::KeyF => 'f',
83            Code::KeyG => 'g',
84            Code::KeyH => 'h',
85            Code::KeyI => 'i',
86            Code::KeyJ => 'j',
87            Code::KeyK => 'k',
88            Code::KeyL => 'l',
89            Code::KeyM => 'm',
90            Code::KeyN => 'n',
91            Code::KeyO => 'o',
92            Code::KeyP => 'p',
93            Code::KeyQ => 'q',
94            Code::KeyR => 'r',
95            Code::KeyS => 's',
96            Code::KeyT => 't',
97            Code::KeyU => 'u',
98            Code::KeyV => 'v',
99            Code::KeyW => 'w',
100            Code::KeyX => 'x',
101            Code::KeyY => 'y',
102            Code::KeyZ => 'z',
103            Code::Digit0 => '0',
104            Code::Digit1 => '1',
105            Code::Digit2 => '2',
106            Code::Digit3 => '3',
107            Code::Digit4 => '4',
108            Code::Digit5 => '5',
109            Code::Digit6 => '6',
110            Code::Digit7 => '7',
111            Code::Digit8 => '8',
112            Code::Digit9 => '9',
113            _ => return None,
114        };
115
116        Some(latin)
117    }
118}
119
120impl From<Named> for Key {
121    fn from(named: Named) -> Self {
122        Self::Named(named)
123    }
124}
125
126/// A named key.
127///
128/// This is mostly the `NamedKey` type found in [`winit`].
129///
130/// [`winit`]: https://docs.rs/winit/0.29.10/winit/keyboard/enum.Key.html
131#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
132#[allow(missing_docs)]
133pub enum Named {
134    /// The `Alt` (Alternative) key.
135    ///
136    /// This key enables the alternate modifier function for interpreting concurrent or subsequent
137    /// keyboard input. This key value is also used for the Apple <kbd>Option</kbd> key.
138    Alt,
139    /// The Alternate Graphics (<kbd>AltGr</kbd> or <kbd>AltGraph</kbd>) key.
140    ///
141    /// This key is used enable the ISO Level 3 shift modifier (the standard `Shift` key is the
142    /// level 2 modifier).
143    AltGraph,
144    /// The `Caps Lock` (Capital) key.
145    ///
146    /// Toggle capital character lock function for interpreting subsequent keyboard input event.
147    CapsLock,
148    /// The `Control` or `Ctrl` key.
149    ///
150    /// Used to enable control modifier function for interpreting concurrent or subsequent keyboard
151    /// input.
152    Control,
153    /// The Function switch `Fn` key. Activating this key simultaneously with another key changes
154    /// that key’s value to an alternate character or function. This key is often handled directly
155    /// in the keyboard hardware and does not usually generate key events.
156    Fn,
157    /// The Function-Lock (`FnLock` or `F-Lock`) key. Activating this key switches the mode of the
158    /// keyboard to changes some keys' values to an alternate character or function. This key is
159    /// often handled directly in the keyboard hardware and does not usually generate key events.
160    FnLock,
161    /// The `NumLock` or Number Lock key. Used to toggle numpad mode function for interpreting
162    /// subsequent keyboard input.
163    NumLock,
164    /// Toggle between scrolling and cursor movement modes.
165    ScrollLock,
166    /// Used to enable shift modifier function for interpreting concurrent or subsequent keyboard
167    /// input.
168    Shift,
169    /// The Symbol modifier key (used on some virtual keyboards).
170    Symbol,
171    SymbolLock,
172    // Legacy modifier key. Also called "Super" in certain places.
173    Meta,
174    // Legacy modifier key.
175    Hyper,
176    /// Used to enable "super" modifier function for interpreting concurrent or subsequent keyboard
177    /// input. This key value is used for the "Windows Logo" key and the Apple `Command` or `⌘` key.
178    ///
179    /// Note: In some contexts (e.g. the Web) this is referred to as the "Meta" key.
180    Super,
181    /// The `Enter` or `↵` key. Used to activate current selection or accept current input. This key
182    /// value is also used for the `Return` (Macintosh numpad) key. This key value is also used for
183    /// the Android `KEYCODE_DPAD_CENTER`.
184    Enter,
185    /// The Horizontal Tabulation `Tab` key.
186    Tab,
187    /// Used in text to insert a space between words. Usually located below the character keys.
188    Space,
189    /// Navigate or traverse downward. (`KEYCODE_DPAD_DOWN`)
190    ArrowDown,
191    /// Navigate or traverse leftward. (`KEYCODE_DPAD_LEFT`)
192    ArrowLeft,
193    /// Navigate or traverse rightward. (`KEYCODE_DPAD_RIGHT`)
194    ArrowRight,
195    /// Navigate or traverse upward. (`KEYCODE_DPAD_UP`)
196    ArrowUp,
197    /// The End key, used with keyboard entry to go to the end of content (`KEYCODE_MOVE_END`).
198    End,
199    /// The Home key, used with keyboard entry, to go to start of content (`KEYCODE_MOVE_HOME`).
200    /// For the mobile phone `Home` key (which goes to the phone’s main screen), use [`GoHome`].
201    ///
202    /// [`GoHome`]: Self::GoHome
203    Home,
204    /// Scroll down or display next page of content.
205    PageDown,
206    /// Scroll up or display previous page of content.
207    PageUp,
208    /// Used to remove the character to the left of the cursor. This key value is also used for
209    /// the key labeled `Delete` on MacOS keyboards.
210    Backspace,
211    /// Remove the currently selected input.
212    Clear,
213    /// Copy the current selection. (`APPCOMMAND_COPY`)
214    Copy,
215    /// The Cursor Select key.
216    CrSel,
217    /// Cut the current selection. (`APPCOMMAND_CUT`)
218    Cut,
219    /// Used to delete the character to the right of the cursor. This key value is also used for the
220    /// key labeled `Delete` on MacOS keyboards when `Fn` is active.
221    Delete,
222    /// The Erase to End of Field key. This key deletes all characters from the current cursor
223    /// position to the end of the current field.
224    EraseEof,
225    /// The Extend Selection (Exsel) key.
226    ExSel,
227    /// Toggle between text modes for insertion or overtyping.
228    /// (`KEYCODE_INSERT`)
229    Insert,
230    /// The Paste key. (`APPCOMMAND_PASTE`)
231    Paste,
232    /// Redo the last action. (`APPCOMMAND_REDO`)
233    Redo,
234    /// Undo the last action. (`APPCOMMAND_UNDO`)
235    Undo,
236    /// The Accept (Commit, OK) key. Accept current option or input method sequence conversion.
237    Accept,
238    /// Redo or repeat an action.
239    Again,
240    /// The Attention (Attn) key.
241    Attn,
242    Cancel,
243    /// Show the application’s context menu.
244    /// This key is commonly found between the right `Super` key and the right `Control` key.
245    ContextMenu,
246    /// The `Esc` key. This key was originally used to initiate an escape sequence, but is
247    /// now more generally used to exit or "escape" the current context, such as closing a dialog
248    /// or exiting full screen mode.
249    Escape,
250    Execute,
251    /// Open the Find dialog. (`APPCOMMAND_FIND`)
252    Find,
253    /// Open a help dialog or toggle display of help information. (`APPCOMMAND_HELP`,
254    /// `KEYCODE_HELP`)
255    Help,
256    /// Pause the current state or application (as appropriate).
257    ///
258    /// Note: Do not use this value for the `Pause` button on media controllers. Use `"MediaPause"`
259    /// instead.
260    Pause,
261    /// Play or resume the current state or application (as appropriate).
262    ///
263    /// Note: Do not use this value for the `Play` button on media controllers. Use `"MediaPlay"`
264    /// instead.
265    Play,
266    /// The properties (Props) key.
267    Props,
268    Select,
269    /// The ZoomIn key. (`KEYCODE_ZOOM_IN`)
270    ZoomIn,
271    /// The ZoomOut key. (`KEYCODE_ZOOM_OUT`)
272    ZoomOut,
273    /// The Brightness Down key. Typically controls the display brightness.
274    /// (`KEYCODE_BRIGHTNESS_DOWN`)
275    BrightnessDown,
276    /// The Brightness Up key. Typically controls the display brightness. (`KEYCODE_BRIGHTNESS_UP`)
277    BrightnessUp,
278    /// Toggle removable media to eject (open) and insert (close) state. (`KEYCODE_MEDIA_EJECT`)
279    Eject,
280    LogOff,
281    /// Toggle power state. (`KEYCODE_POWER`)
282    /// Note: Note: Some devices might not expose this key to the operating environment.
283    Power,
284    /// The `PowerOff` key. Sometime called `PowerDown`.
285    PowerOff,
286    /// Initiate print-screen function.
287    PrintScreen,
288    /// The Hibernate key. This key saves the current state of the computer to disk so that it can
289    /// be restored. The computer will then shutdown.
290    Hibernate,
291    /// The Standby key. This key turns off the display and places the computer into a low-power
292    /// mode without completely shutting down. It is sometimes labelled `Suspend` or `Sleep` key.
293    /// (`KEYCODE_SLEEP`)
294    Standby,
295    /// The WakeUp key. (`KEYCODE_WAKEUP`)
296    WakeUp,
297    /// Initiate the multi-candidate mode.
298    AllCandidates,
299    Alphanumeric,
300    /// Initiate the Code Input mode to allow characters to be entered by
301    /// their code points.
302    CodeInput,
303    /// The Compose key, also known as "Multi_key" on the X Window System. This key acts in a
304    /// manner similar to a dead key, triggering a mode where subsequent key presses are combined to
305    /// produce a different character.
306    Compose,
307    /// Convert the current input method sequence.
308    Convert,
309    /// The Final Mode `Final` key used on some Asian keyboards, to enable the final mode for IMEs.
310    FinalMode,
311    /// Switch to the first character group. (ISO/IEC 9995)
312    GroupFirst,
313    /// Switch to the last character group. (ISO/IEC 9995)
314    GroupLast,
315    /// Switch to the next character group. (ISO/IEC 9995)
316    GroupNext,
317    /// Switch to the previous character group. (ISO/IEC 9995)
318    GroupPrevious,
319    /// Toggle between or cycle through input modes of IMEs.
320    ModeChange,
321    NextCandidate,
322    /// Accept current input method sequence without
323    /// conversion in IMEs.
324    NonConvert,
325    PreviousCandidate,
326    Process,
327    SingleCandidate,
328    /// Toggle between Hangul and English modes.
329    HangulMode,
330    HanjaMode,
331    JunjaMode,
332    /// The Eisu key. This key may close the IME, but its purpose is defined by the current IME.
333    /// (`KEYCODE_EISU`)
334    Eisu,
335    /// The (Half-Width) Characters key.
336    Hankaku,
337    /// The Hiragana (Japanese Kana characters) key.
338    Hiragana,
339    /// The Hiragana/Katakana toggle key. (`KEYCODE_KATAKANA_HIRAGANA`)
340    HiraganaKatakana,
341    /// The Kana Mode (Kana Lock) key. This key is used to enter hiragana mode (typically from
342    /// romaji mode).
343    KanaMode,
344    /// The Kanji (Japanese name for ideographic characters of Chinese origin) Mode key. This key is
345    /// typically used to switch to a hiragana keyboard for the purpose of converting input into
346    /// kanji. (`KEYCODE_KANA`)
347    KanjiMode,
348    /// The Katakana (Japanese Kana characters) key.
349    Katakana,
350    /// The Roman characters function key.
351    Romaji,
352    /// The Zenkaku (Full-Width) Characters key.
353    Zenkaku,
354    /// The Zenkaku/Hankaku (full-width/half-width) toggle key. (`KEYCODE_ZENKAKU_HANKAKU`)
355    ZenkakuHankaku,
356    /// General purpose virtual function key, as index 1.
357    Soft1,
358    /// General purpose virtual function key, as index 2.
359    Soft2,
360    /// General purpose virtual function key, as index 3.
361    Soft3,
362    /// General purpose virtual function key, as index 4.
363    Soft4,
364    /// Select next (numerically or logically) lower channel. (`APPCOMMAND_MEDIA_CHANNEL_DOWN`,
365    /// `KEYCODE_CHANNEL_DOWN`)
366    ChannelDown,
367    /// Select next (numerically or logically) higher channel. (`APPCOMMAND_MEDIA_CHANNEL_UP`,
368    /// `KEYCODE_CHANNEL_UP`)
369    ChannelUp,
370    /// Close the current document or message (Note: This doesn’t close the application).
371    /// (`APPCOMMAND_CLOSE`)
372    Close,
373    /// Open an editor to forward the current message. (`APPCOMMAND_FORWARD_MAIL`)
374    MailForward,
375    /// Open an editor to reply to the current message. (`APPCOMMAND_REPLY_TO_MAIL`)
376    MailReply,
377    /// Send the current message. (`APPCOMMAND_SEND_MAIL`)
378    MailSend,
379    /// Close the current media, for example to close a CD or DVD tray. (`KEYCODE_MEDIA_CLOSE`)
380    MediaClose,
381    /// Initiate or continue forward playback at faster than normal speed, or increase speed if
382    /// already fast forwarding. (`APPCOMMAND_MEDIA_FAST_FORWARD`, `KEYCODE_MEDIA_FAST_FORWARD`)
383    MediaFastForward,
384    /// Pause the currently playing media. (`APPCOMMAND_MEDIA_PAUSE`, `KEYCODE_MEDIA_PAUSE`)
385    ///
386    /// Note: Media controller devices should use this value rather than `"Pause"` for their pause
387    /// keys.
388    MediaPause,
389    /// Initiate or continue media playback at normal speed, if not currently playing at normal
390    /// speed. (`APPCOMMAND_MEDIA_PLAY`, `KEYCODE_MEDIA_PLAY`)
391    MediaPlay,
392    /// Toggle media between play and pause states. (`APPCOMMAND_MEDIA_PLAY_PAUSE`,
393    /// `KEYCODE_MEDIA_PLAY_PAUSE`)
394    MediaPlayPause,
395    /// Initiate or resume recording of currently selected media. (`APPCOMMAND_MEDIA_RECORD`,
396    /// `KEYCODE_MEDIA_RECORD`)
397    MediaRecord,
398    /// Initiate or continue reverse playback at faster than normal speed, or increase speed if
399    /// already rewinding. (`APPCOMMAND_MEDIA_REWIND`, `KEYCODE_MEDIA_REWIND`)
400    MediaRewind,
401    /// Stop media playing, pausing, forwarding, rewinding, or recording, if not already stopped.
402    /// (`APPCOMMAND_MEDIA_STOP`, `KEYCODE_MEDIA_STOP`)
403    MediaStop,
404    /// Seek to next media or program track. (`APPCOMMAND_MEDIA_NEXTTRACK`, `KEYCODE_MEDIA_NEXT`)
405    MediaTrackNext,
406    /// Seek to previous media or program track. (`APPCOMMAND_MEDIA_PREVIOUSTRACK`,
407    /// `KEYCODE_MEDIA_PREVIOUS`)
408    MediaTrackPrevious,
409    /// Open a new document or message. (`APPCOMMAND_NEW`)
410    New,
411    /// Open an existing document or message. (`APPCOMMAND_OPEN`)
412    Open,
413    /// Print the current document or message. (`APPCOMMAND_PRINT`)
414    Print,
415    /// Save the current document or message. (`APPCOMMAND_SAVE`)
416    Save,
417    /// Spellcheck the current document or selection. (`APPCOMMAND_SPELL_CHECK`)
418    SpellCheck,
419    /// The `11` key found on media numpads that
420    /// have buttons from `1` ... `12`.
421    Key11,
422    /// The `12` key found on media numpads that
423    /// have buttons from `1` ... `12`.
424    Key12,
425    /// Adjust audio balance leftward. (`VK_AUDIO_BALANCE_LEFT`)
426    AudioBalanceLeft,
427    /// Adjust audio balance rightward. (`VK_AUDIO_BALANCE_RIGHT`)
428    AudioBalanceRight,
429    /// Decrease audio bass boost or cycle down through bass boost states. (`APPCOMMAND_BASS_DOWN`,
430    /// `VK_BASS_BOOST_DOWN`)
431    AudioBassBoostDown,
432    /// Toggle bass boost on/off. (`APPCOMMAND_BASS_BOOST`)
433    AudioBassBoostToggle,
434    /// Increase audio bass boost or cycle up through bass boost states. (`APPCOMMAND_BASS_UP`,
435    /// `VK_BASS_BOOST_UP`)
436    AudioBassBoostUp,
437    /// Adjust audio fader towards front. (`VK_FADER_FRONT`)
438    AudioFaderFront,
439    /// Adjust audio fader towards rear. (`VK_FADER_REAR`)
440    AudioFaderRear,
441    /// Advance surround audio mode to next available mode. (`VK_SURROUND_MODE_NEXT`)
442    AudioSurroundModeNext,
443    /// Decrease treble. (`APPCOMMAND_TREBLE_DOWN`)
444    AudioTrebleDown,
445    /// Increase treble. (`APPCOMMAND_TREBLE_UP`)
446    AudioTrebleUp,
447    /// Decrease audio volume. (`APPCOMMAND_VOLUME_DOWN`, `KEYCODE_VOLUME_DOWN`)
448    AudioVolumeDown,
449    /// Increase audio volume. (`APPCOMMAND_VOLUME_UP`, `KEYCODE_VOLUME_UP`)
450    AudioVolumeUp,
451    /// Toggle between muted state and prior volume level. (`APPCOMMAND_VOLUME_MUTE`,
452    /// `KEYCODE_VOLUME_MUTE`)
453    AudioVolumeMute,
454    /// Toggle the microphone on/off. (`APPCOMMAND_MIC_ON_OFF_TOGGLE`)
455    MicrophoneToggle,
456    /// Decrease microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_DOWN`)
457    MicrophoneVolumeDown,
458    /// Increase microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_UP`)
459    MicrophoneVolumeUp,
460    /// Mute the microphone. (`APPCOMMAND_MICROPHONE_VOLUME_MUTE`, `KEYCODE_MUTE`)
461    MicrophoneVolumeMute,
462    /// Show correction list when a word is incorrectly identified. (`APPCOMMAND_CORRECTION_LIST`)
463    SpeechCorrectionList,
464    /// Toggle between dictation mode and command/control mode.
465    /// (`APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE`)
466    SpeechInputToggle,
467    /// The first generic "LaunchApplication" key. This is commonly associated with launching "My
468    /// Computer", and may have a computer symbol on the key. (`APPCOMMAND_LAUNCH_APP1`)
469    LaunchApplication1,
470    /// The second generic "LaunchApplication" key. This is commonly associated with launching
471    /// "Calculator", and may have a calculator symbol on the key. (`APPCOMMAND_LAUNCH_APP2`,
472    /// `KEYCODE_CALCULATOR`)
473    LaunchApplication2,
474    /// The "Calendar" key. (`KEYCODE_CALENDAR`)
475    LaunchCalendar,
476    /// The "Contacts" key. (`KEYCODE_CONTACTS`)
477    LaunchContacts,
478    /// The "Mail" key. (`APPCOMMAND_LAUNCH_MAIL`)
479    LaunchMail,
480    /// The "Media Player" key. (`APPCOMMAND_LAUNCH_MEDIA_SELECT`)
481    LaunchMediaPlayer,
482    LaunchMusicPlayer,
483    LaunchPhone,
484    LaunchScreenSaver,
485    LaunchSpreadsheet,
486    LaunchWebBrowser,
487    LaunchWebCam,
488    LaunchWordProcessor,
489    /// Navigate to previous content or page in current history. (`APPCOMMAND_BROWSER_BACKWARD`)
490    BrowserBack,
491    /// Open the list of browser favorites. (`APPCOMMAND_BROWSER_FAVORITES`)
492    BrowserFavorites,
493    /// Navigate to next content or page in current history. (`APPCOMMAND_BROWSER_FORWARD`)
494    BrowserForward,
495    /// Go to the user’s preferred home page. (`APPCOMMAND_BROWSER_HOME`)
496    BrowserHome,
497    /// Refresh the current page or content. (`APPCOMMAND_BROWSER_REFRESH`)
498    BrowserRefresh,
499    /// Call up the user’s preferred search page. (`APPCOMMAND_BROWSER_SEARCH`)
500    BrowserSearch,
501    /// Stop loading the current page or content. (`APPCOMMAND_BROWSER_STOP`)
502    BrowserStop,
503    /// The Application switch key, which provides a list of recent apps to switch between.
504    /// (`KEYCODE_APP_SWITCH`)
505    AppSwitch,
506    /// The Call key. (`KEYCODE_CALL`)
507    Call,
508    /// The Camera key. (`KEYCODE_CAMERA`)
509    Camera,
510    /// The Camera focus key. (`KEYCODE_FOCUS`)
511    CameraFocus,
512    /// The End Call key. (`KEYCODE_ENDCALL`)
513    EndCall,
514    /// The Back key. (`KEYCODE_BACK`)
515    GoBack,
516    /// The Home key, which goes to the phone’s main screen. (`KEYCODE_HOME`)
517    GoHome,
518    /// The Headset Hook key. (`KEYCODE_HEADSETHOOK`)
519    HeadsetHook,
520    LastNumberRedial,
521    /// The Notification key. (`KEYCODE_NOTIFICATION`)
522    Notification,
523    /// Toggle between manner mode state: silent, vibrate, ring, ... (`KEYCODE_MANNER_MODE`)
524    MannerMode,
525    VoiceDial,
526    /// Switch to viewing TV. (`KEYCODE_TV`)
527    TV,
528    /// TV 3D Mode. (`KEYCODE_3D_MODE`)
529    TV3DMode,
530    /// Toggle between antenna and cable input. (`KEYCODE_TV_ANTENNA_CABLE`)
531    TVAntennaCable,
532    /// Audio description. (`KEYCODE_TV_AUDIO_DESCRIPTION`)
533    TVAudioDescription,
534    /// Audio description mixing volume down. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN`)
535    TVAudioDescriptionMixDown,
536    /// Audio description mixing volume up. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP`)
537    TVAudioDescriptionMixUp,
538    /// Contents menu. (`KEYCODE_TV_CONTENTS_MENU`)
539    TVContentsMenu,
540    /// Contents menu. (`KEYCODE_TV_DATA_SERVICE`)
541    TVDataService,
542    /// Switch the input mode on an external TV. (`KEYCODE_TV_INPUT`)
543    TVInput,
544    /// Switch to component input #1. (`KEYCODE_TV_INPUT_COMPONENT_1`)
545    TVInputComponent1,
546    /// Switch to component input #2. (`KEYCODE_TV_INPUT_COMPONENT_2`)
547    TVInputComponent2,
548    /// Switch to composite input #1. (`KEYCODE_TV_INPUT_COMPOSITE_1`)
549    TVInputComposite1,
550    /// Switch to composite input #2. (`KEYCODE_TV_INPUT_COMPOSITE_2`)
551    TVInputComposite2,
552    /// Switch to HDMI input #1. (`KEYCODE_TV_INPUT_HDMI_1`)
553    TVInputHDMI1,
554    /// Switch to HDMI input #2. (`KEYCODE_TV_INPUT_HDMI_2`)
555    TVInputHDMI2,
556    /// Switch to HDMI input #3. (`KEYCODE_TV_INPUT_HDMI_3`)
557    TVInputHDMI3,
558    /// Switch to HDMI input #4. (`KEYCODE_TV_INPUT_HDMI_4`)
559    TVInputHDMI4,
560    /// Switch to VGA input #1. (`KEYCODE_TV_INPUT_VGA_1`)
561    TVInputVGA1,
562    /// Media context menu. (`KEYCODE_TV_MEDIA_CONTEXT_MENU`)
563    TVMediaContext,
564    /// Toggle network. (`KEYCODE_TV_NETWORK`)
565    TVNetwork,
566    /// Number entry. (`KEYCODE_TV_NUMBER_ENTRY`)
567    TVNumberEntry,
568    /// Toggle the power on an external TV. (`KEYCODE_TV_POWER`)
569    TVPower,
570    /// Radio. (`KEYCODE_TV_RADIO_SERVICE`)
571    TVRadioService,
572    /// Satellite. (`KEYCODE_TV_SATELLITE`)
573    TVSatellite,
574    /// Broadcast Satellite. (`KEYCODE_TV_SATELLITE_BS`)
575    TVSatelliteBS,
576    /// Communication Satellite. (`KEYCODE_TV_SATELLITE_CS`)
577    TVSatelliteCS,
578    /// Toggle between available satellites. (`KEYCODE_TV_SATELLITE_SERVICE`)
579    TVSatelliteToggle,
580    /// Analog Terrestrial. (`KEYCODE_TV_TERRESTRIAL_ANALOG`)
581    TVTerrestrialAnalog,
582    /// Digital Terrestrial. (`KEYCODE_TV_TERRESTRIAL_DIGITAL`)
583    TVTerrestrialDigital,
584    /// Timer programming. (`KEYCODE_TV_TIMER_PROGRAMMING`)
585    TVTimer,
586    /// Switch the input mode on an external AVR (audio/video receiver). (`KEYCODE_AVR_INPUT`)
587    AVRInput,
588    /// Toggle the power on an external AVR (audio/video receiver). (`KEYCODE_AVR_POWER`)
589    AVRPower,
590    /// General purpose color-coded media function key, as index 0 (red). (`VK_COLORED_KEY_0`,
591    /// `KEYCODE_PROG_RED`)
592    ColorF0Red,
593    /// General purpose color-coded media function key, as index 1 (green). (`VK_COLORED_KEY_1`,
594    /// `KEYCODE_PROG_GREEN`)
595    ColorF1Green,
596    /// General purpose color-coded media function key, as index 2 (yellow). (`VK_COLORED_KEY_2`,
597    /// `KEYCODE_PROG_YELLOW`)
598    ColorF2Yellow,
599    /// General purpose color-coded media function key, as index 3 (blue). (`VK_COLORED_KEY_3`,
600    /// `KEYCODE_PROG_BLUE`)
601    ColorF3Blue,
602    /// General purpose color-coded media function key, as index 4 (grey). (`VK_COLORED_KEY_4`)
603    ColorF4Grey,
604    /// General purpose color-coded media function key, as index 5 (brown). (`VK_COLORED_KEY_5`)
605    ColorF5Brown,
606    /// Toggle the display of Closed Captions. (`VK_CC`, `KEYCODE_CAPTIONS`)
607    ClosedCaptionToggle,
608    /// Adjust brightness of device, by toggling between or cycling through states. (`VK_DIMMER`)
609    Dimmer,
610    /// Swap video sources. (`VK_DISPLAY_SWAP`)
611    DisplaySwap,
612    /// Select Digital Video Rrecorder. (`KEYCODE_DVR`)
613    DVR,
614    /// Exit the current application. (`VK_EXIT`)
615    Exit,
616    /// Clear program or content stored as favorite 0. (`VK_CLEAR_FAVORITE_0`)
617    FavoriteClear0,
618    /// Clear program or content stored as favorite 1. (`VK_CLEAR_FAVORITE_1`)
619    FavoriteClear1,
620    /// Clear program or content stored as favorite 2. (`VK_CLEAR_FAVORITE_2`)
621    FavoriteClear2,
622    /// Clear program or content stored as favorite 3. (`VK_CLEAR_FAVORITE_3`)
623    FavoriteClear3,
624    /// Select (recall) program or content stored as favorite 0. (`VK_RECALL_FAVORITE_0`)
625    FavoriteRecall0,
626    /// Select (recall) program or content stored as favorite 1. (`VK_RECALL_FAVORITE_1`)
627    FavoriteRecall1,
628    /// Select (recall) program or content stored as favorite 2. (`VK_RECALL_FAVORITE_2`)
629    FavoriteRecall2,
630    /// Select (recall) program or content stored as favorite 3. (`VK_RECALL_FAVORITE_3`)
631    FavoriteRecall3,
632    /// Store current program or content as favorite 0. (`VK_STORE_FAVORITE_0`)
633    FavoriteStore0,
634    /// Store current program or content as favorite 1. (`VK_STORE_FAVORITE_1`)
635    FavoriteStore1,
636    /// Store current program or content as favorite 2. (`VK_STORE_FAVORITE_2`)
637    FavoriteStore2,
638    /// Store current program or content as favorite 3. (`VK_STORE_FAVORITE_3`)
639    FavoriteStore3,
640    /// Toggle display of program or content guide. (`VK_GUIDE`, `KEYCODE_GUIDE`)
641    Guide,
642    /// If guide is active and displayed, then display next day’s content. (`VK_NEXT_DAY`)
643    GuideNextDay,
644    /// If guide is active and displayed, then display previous day’s content. (`VK_PREV_DAY`)
645    GuidePreviousDay,
646    /// Toggle display of information about currently selected context or media. (`VK_INFO`,
647    /// `KEYCODE_INFO`)
648    Info,
649    /// Toggle instant replay. (`VK_INSTANT_REPLAY`)
650    InstantReplay,
651    /// Launch linked content, if available and appropriate. (`VK_LINK`)
652    Link,
653    /// List the current program. (`VK_LIST`)
654    ListProgram,
655    /// Toggle display listing of currently available live content or programs. (`VK_LIVE`)
656    LiveContent,
657    /// Lock or unlock current content or program. (`VK_LOCK`)
658    Lock,
659    /// Show a list of media applications: audio/video players and image viewers. (`VK_APPS`)
660    ///
661    /// Note: Do not confuse this key value with the Windows' `VK_APPS` / `VK_CONTEXT_MENU` key,
662    /// which is encoded as `"ContextMenu"`.
663    MediaApps,
664    /// Audio track key. (`KEYCODE_MEDIA_AUDIO_TRACK`)
665    MediaAudioTrack,
666    /// Select previously selected channel or media. (`VK_LAST`, `KEYCODE_LAST_CHANNEL`)
667    MediaLast,
668    /// Skip backward to next content or program. (`KEYCODE_MEDIA_SKIP_BACKWARD`)
669    MediaSkipBackward,
670    /// Skip forward to next content or program. (`VK_SKIP`, `KEYCODE_MEDIA_SKIP_FORWARD`)
671    MediaSkipForward,
672    /// Step backward to next content or program. (`KEYCODE_MEDIA_STEP_BACKWARD`)
673    MediaStepBackward,
674    /// Step forward to next content or program. (`KEYCODE_MEDIA_STEP_FORWARD`)
675    MediaStepForward,
676    /// Media top menu. (`KEYCODE_MEDIA_TOP_MENU`)
677    MediaTopMenu,
678    /// Navigate in. (`KEYCODE_NAVIGATE_IN`)
679    NavigateIn,
680    /// Navigate to next key. (`KEYCODE_NAVIGATE_NEXT`)
681    NavigateNext,
682    /// Navigate out. (`KEYCODE_NAVIGATE_OUT`)
683    NavigateOut,
684    /// Navigate to previous key. (`KEYCODE_NAVIGATE_PREVIOUS`)
685    NavigatePrevious,
686    /// Cycle to next favorite channel (in favorites list). (`VK_NEXT_FAVORITE_CHANNEL`)
687    NextFavoriteChannel,
688    /// Cycle to next user profile (if there are multiple user profiles). (`VK_USER`)
689    NextUserProfile,
690    /// Access on-demand content or programs. (`VK_ON_DEMAND`)
691    OnDemand,
692    /// Pairing key to pair devices. (`KEYCODE_PAIRING`)
693    Pairing,
694    /// Move picture-in-picture window down. (`VK_PINP_DOWN`)
695    PinPDown,
696    /// Move picture-in-picture window. (`VK_PINP_MOVE`)
697    PinPMove,
698    /// Toggle display of picture-in-picture window. (`VK_PINP_TOGGLE`)
699    PinPToggle,
700    /// Move picture-in-picture window up. (`VK_PINP_UP`)
701    PinPUp,
702    /// Decrease media playback speed. (`VK_PLAY_SPEED_DOWN`)
703    PlaySpeedDown,
704    /// Reset playback to normal speed. (`VK_PLAY_SPEED_RESET`)
705    PlaySpeedReset,
706    /// Increase media playback speed. (`VK_PLAY_SPEED_UP`)
707    PlaySpeedUp,
708    /// Toggle random media or content shuffle mode. (`VK_RANDOM_TOGGLE`)
709    RandomToggle,
710    /// Not a physical key, but this key code is sent when the remote control battery is low.
711    /// (`VK_RC_LOW_BATTERY`)
712    RcLowBattery,
713    /// Toggle or cycle between media recording speeds. (`VK_RECORD_SPEED_NEXT`)
714    RecordSpeedNext,
715    /// Toggle RF (radio frequency) input bypass mode (pass RF input directly to the RF output).
716    /// (`VK_RF_BYPASS`)
717    RfBypass,
718    /// Toggle scan channels mode. (`VK_SCAN_CHANNELS_TOGGLE`)
719    ScanChannelsToggle,
720    /// Advance display screen mode to next available mode. (`VK_SCREEN_MODE_NEXT`)
721    ScreenModeNext,
722    /// Toggle display of device settings screen. (`VK_SETTINGS`, `KEYCODE_SETTINGS`)
723    Settings,
724    /// Toggle split screen mode. (`VK_SPLIT_SCREEN_TOGGLE`)
725    SplitScreenToggle,
726    /// Switch the input mode on an external STB (set top box). (`KEYCODE_STB_INPUT`)
727    STBInput,
728    /// Toggle the power on an external STB (set top box). (`KEYCODE_STB_POWER`)
729    STBPower,
730    /// Toggle display of subtitles, if available. (`VK_SUBTITLE`)
731    Subtitle,
732    /// Toggle display of teletext, if available (`VK_TELETEXT`, `KEYCODE_TV_TELETEXT`).
733    Teletext,
734    /// Advance video mode to next available mode. (`VK_VIDEO_MODE_NEXT`)
735    VideoModeNext,
736    /// Cause device to identify itself in some manner, e.g., audibly or visibly. (`VK_WINK`)
737    Wink,
738    /// Toggle between full-screen and scaled content, or alter magnification level. (`VK_ZOOM`,
739    /// `KEYCODE_TV_ZOOM_MODE`)
740    ZoomToggle,
741    /// General-purpose function key.
742    /// Usually found at the top of the keyboard.
743    F1,
744    /// General-purpose function key.
745    /// Usually found at the top of the keyboard.
746    F2,
747    /// General-purpose function key.
748    /// Usually found at the top of the keyboard.
749    F3,
750    /// General-purpose function key.
751    /// Usually found at the top of the keyboard.
752    F4,
753    /// General-purpose function key.
754    /// Usually found at the top of the keyboard.
755    F5,
756    /// General-purpose function key.
757    /// Usually found at the top of the keyboard.
758    F6,
759    /// General-purpose function key.
760    /// Usually found at the top of the keyboard.
761    F7,
762    /// General-purpose function key.
763    /// Usually found at the top of the keyboard.
764    F8,
765    /// General-purpose function key.
766    /// Usually found at the top of the keyboard.
767    F9,
768    /// General-purpose function key.
769    /// Usually found at the top of the keyboard.
770    F10,
771    /// General-purpose function key.
772    /// Usually found at the top of the keyboard.
773    F11,
774    /// General-purpose function key.
775    /// Usually found at the top of the keyboard.
776    F12,
777    /// General-purpose function key.
778    /// Usually found at the top of the keyboard.
779    F13,
780    /// General-purpose function key.
781    /// Usually found at the top of the keyboard.
782    F14,
783    /// General-purpose function key.
784    /// Usually found at the top of the keyboard.
785    F15,
786    /// General-purpose function key.
787    /// Usually found at the top of the keyboard.
788    F16,
789    /// General-purpose function key.
790    /// Usually found at the top of the keyboard.
791    F17,
792    /// General-purpose function key.
793    /// Usually found at the top of the keyboard.
794    F18,
795    /// General-purpose function key.
796    /// Usually found at the top of the keyboard.
797    F19,
798    /// General-purpose function key.
799    /// Usually found at the top of the keyboard.
800    F20,
801    /// General-purpose function key.
802    /// Usually found at the top of the keyboard.
803    F21,
804    /// General-purpose function key.
805    /// Usually found at the top of the keyboard.
806    F22,
807    /// General-purpose function key.
808    /// Usually found at the top of the keyboard.
809    F23,
810    /// General-purpose function key.
811    /// Usually found at the top of the keyboard.
812    F24,
813    /// General-purpose function key.
814    F25,
815    /// General-purpose function key.
816    F26,
817    /// General-purpose function key.
818    F27,
819    /// General-purpose function key.
820    F28,
821    /// General-purpose function key.
822    F29,
823    /// General-purpose function key.
824    F30,
825    /// General-purpose function key.
826    F31,
827    /// General-purpose function key.
828    F32,
829    /// General-purpose function key.
830    F33,
831    /// General-purpose function key.
832    F34,
833    /// General-purpose function key.
834    F35,
835}
836
837/// Code representing the location of a physical key.
838///
839/// This mostly conforms to the UI Events Specification's [`KeyboardEvent.code`] with a few
840/// exceptions:
841/// - The keys that the specification calls "MetaLeft" and "MetaRight" are named "SuperLeft" and
842///   "SuperRight" here.
843/// - The key that the specification calls "Super" is reported as `Unidentified` here.
844///
845/// [`KeyboardEvent.code`]: https://w3c.github.io/uievents-code/#code-value-tables
846#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
847#[allow(missing_docs)]
848#[non_exhaustive]
849pub enum Code {
850    /// <kbd>`</kbd> on a US keyboard. This is also called a backtick or grave.
851    /// This is the <kbd>半角</kbd>/<kbd>全角</kbd>/<kbd>漢字</kbd>
852    /// (hankaku/zenkaku/kanji) key on Japanese keyboards
853    Backquote,
854    /// Used for both the US <kbd>\\</kbd> (on the 101-key layout) and also for the key
855    /// located between the <kbd>"</kbd> and <kbd>Enter</kbd> keys on row C of the 102-,
856    /// 104- and 106-key layouts.
857    /// Labeled <kbd>#</kbd> on a UK (102) keyboard.
858    Backslash,
859    /// <kbd>[</kbd> on a US keyboard.
860    BracketLeft,
861    /// <kbd>]</kbd> on a US keyboard.
862    BracketRight,
863    /// <kbd>,</kbd> on a US keyboard.
864    Comma,
865    /// <kbd>0</kbd> on a US keyboard.
866    Digit0,
867    /// <kbd>1</kbd> on a US keyboard.
868    Digit1,
869    /// <kbd>2</kbd> on a US keyboard.
870    Digit2,
871    /// <kbd>3</kbd> on a US keyboard.
872    Digit3,
873    /// <kbd>4</kbd> on a US keyboard.
874    Digit4,
875    /// <kbd>5</kbd> on a US keyboard.
876    Digit5,
877    /// <kbd>6</kbd> on a US keyboard.
878    Digit6,
879    /// <kbd>7</kbd> on a US keyboard.
880    Digit7,
881    /// <kbd>8</kbd> on a US keyboard.
882    Digit8,
883    /// <kbd>9</kbd> on a US keyboard.
884    Digit9,
885    /// <kbd>=</kbd> on a US keyboard.
886    Equal,
887    /// Located between the left <kbd>Shift</kbd> and <kbd>Z</kbd> keys.
888    /// Labeled <kbd>\\</kbd> on a UK keyboard.
889    IntlBackslash,
890    /// Located between the <kbd>/</kbd> and right <kbd>Shift</kbd> keys.
891    /// Labeled <kbd>\\</kbd> (ro) on a Japanese keyboard.
892    IntlRo,
893    /// Located between the <kbd>=</kbd> and <kbd>Backspace</kbd> keys.
894    /// Labeled <kbd>¥</kbd> (yen) on a Japanese keyboard. <kbd>\\</kbd> on a
895    /// Russian keyboard.
896    IntlYen,
897    /// <kbd>a</kbd> on a US keyboard.
898    /// Labeled <kbd>q</kbd> on an AZERTY (e.g., French) keyboard.
899    KeyA,
900    /// <kbd>b</kbd> on a US keyboard.
901    KeyB,
902    /// <kbd>c</kbd> on a US keyboard.
903    KeyC,
904    /// <kbd>d</kbd> on a US keyboard.
905    KeyD,
906    /// <kbd>e</kbd> on a US keyboard.
907    KeyE,
908    /// <kbd>f</kbd> on a US keyboard.
909    KeyF,
910    /// <kbd>g</kbd> on a US keyboard.
911    KeyG,
912    /// <kbd>h</kbd> on a US keyboard.
913    KeyH,
914    /// <kbd>i</kbd> on a US keyboard.
915    KeyI,
916    /// <kbd>j</kbd> on a US keyboard.
917    KeyJ,
918    /// <kbd>k</kbd> on a US keyboard.
919    KeyK,
920    /// <kbd>l</kbd> on a US keyboard.
921    KeyL,
922    /// <kbd>m</kbd> on a US keyboard.
923    KeyM,
924    /// <kbd>n</kbd> on a US keyboard.
925    KeyN,
926    /// <kbd>o</kbd> on a US keyboard.
927    KeyO,
928    /// <kbd>p</kbd> on a US keyboard.
929    KeyP,
930    /// <kbd>q</kbd> on a US keyboard.
931    /// Labeled <kbd>a</kbd> on an AZERTY (e.g., French) keyboard.
932    KeyQ,
933    /// <kbd>r</kbd> on a US keyboard.
934    KeyR,
935    /// <kbd>s</kbd> on a US keyboard.
936    KeyS,
937    /// <kbd>t</kbd> on a US keyboard.
938    KeyT,
939    /// <kbd>u</kbd> on a US keyboard.
940    KeyU,
941    /// <kbd>v</kbd> on a US keyboard.
942    KeyV,
943    /// <kbd>w</kbd> on a US keyboard.
944    /// Labeled <kbd>z</kbd> on an AZERTY (e.g., French) keyboard.
945    KeyW,
946    /// <kbd>x</kbd> on a US keyboard.
947    KeyX,
948    /// <kbd>y</kbd> on a US keyboard.
949    /// Labeled <kbd>z</kbd> on a QWERTZ (e.g., German) keyboard.
950    KeyY,
951    /// <kbd>z</kbd> on a US keyboard.
952    /// Labeled <kbd>w</kbd> on an AZERTY (e.g., French) keyboard, and <kbd>y</kbd> on a
953    /// QWERTZ (e.g., German) keyboard.
954    KeyZ,
955    /// <kbd>-</kbd> on a US keyboard.
956    Minus,
957    /// <kbd>.</kbd> on a US keyboard.
958    Period,
959    /// <kbd>'</kbd> on a US keyboard.
960    Quote,
961    /// <kbd>;</kbd> on a US keyboard.
962    Semicolon,
963    /// <kbd>/</kbd> on a US keyboard.
964    Slash,
965    /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
966    AltLeft,
967    /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
968    /// This is labeled <kbd>AltGr</kbd> on many keyboard layouts.
969    AltRight,
970    /// <kbd>Backspace</kbd> or <kbd>⌫</kbd>.
971    /// Labeled <kbd>Delete</kbd> on Apple keyboards.
972    Backspace,
973    /// <kbd>CapsLock</kbd> or <kbd>⇪</kbd>
974    CapsLock,
975    /// The application context menu key, which is typically found between the right
976    /// <kbd>Super</kbd> key and the right <kbd>Control</kbd> key.
977    ContextMenu,
978    /// <kbd>Control</kbd> or <kbd>⌃</kbd>
979    ControlLeft,
980    /// <kbd>Control</kbd> or <kbd>⌃</kbd>
981    ControlRight,
982    /// <kbd>Enter</kbd> or <kbd>↵</kbd>. Labeled <kbd>Return</kbd> on Apple keyboards.
983    Enter,
984    /// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
985    SuperLeft,
986    /// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
987    SuperRight,
988    /// <kbd>Shift</kbd> or <kbd>⇧</kbd>
989    ShiftLeft,
990    /// <kbd>Shift</kbd> or <kbd>⇧</kbd>
991    ShiftRight,
992    /// <kbd> </kbd> (space)
993    Space,
994    /// <kbd>Tab</kbd> or <kbd>⇥</kbd>
995    Tab,
996    /// Japanese: <kbd>変</kbd> (henkan)
997    Convert,
998    /// Japanese: <kbd>カタカナ</kbd>/<kbd>ひらがな</kbd>/<kbd>ローマ字</kbd>
999    /// (katakana/hiragana/romaji)
1000    KanaMode,
1001    /// Korean: HangulMode <kbd>한/영</kbd> (han/yeong)
1002    ///
1003    /// Japanese (Mac keyboard): <kbd>か</kbd> (kana)
1004    Lang1,
1005    /// Korean: Hanja <kbd>한</kbd> (hanja)
1006    ///
1007    /// Japanese (Mac keyboard): <kbd>英</kbd> (eisu)
1008    Lang2,
1009    /// Japanese (word-processing keyboard): Katakana
1010    Lang3,
1011    /// Japanese (word-processing keyboard): Hiragana
1012    Lang4,
1013    /// Japanese (word-processing keyboard): Zenkaku/Hankaku
1014    Lang5,
1015    /// Japanese: <kbd>無変換</kbd> (muhenkan)
1016    NonConvert,
1017    /// <kbd>⌦</kbd>. The forward delete key.
1018    /// Note that on Apple keyboards, the key labelled <kbd>Delete</kbd> on the main part of
1019    /// the keyboard is encoded as [`Backspace`].
1020    ///
1021    /// [`Backspace`]: Self::Backspace
1022    Delete,
1023    /// <kbd>Page Down</kbd>, <kbd>End</kbd>, or <kbd>↘</kbd>
1024    End,
1025    /// <kbd>Help</kbd>. Not present on standard PC keyboards.
1026    Help,
1027    /// <kbd>Home</kbd> or <kbd>↖</kbd>
1028    Home,
1029    /// <kbd>Insert</kbd> or <kbd>Ins</kbd>. Not present on Apple keyboards.
1030    Insert,
1031    /// <kbd>Page Down</kbd>, <kbd>PgDn</kbd>, or <kbd>⇟</kbd>
1032    PageDown,
1033    /// <kbd>Page Up</kbd>, <kbd>PgUp</kbd>, or <kbd>⇞</kbd>
1034    PageUp,
1035    /// <kbd>↓</kbd>
1036    ArrowDown,
1037    /// <kbd>←</kbd>
1038    ArrowLeft,
1039    /// <kbd>→</kbd>
1040    ArrowRight,
1041    /// <kbd>↑</kbd>
1042    ArrowUp,
1043    /// On the Mac, this is used for the numpad <kbd>Clear</kbd> key.
1044    NumLock,
1045    /// <kbd>0 Ins</kbd> on a keyboard. <kbd>0</kbd> on a phone or remote control
1046    Numpad0,
1047    /// <kbd>1 End</kbd> on a keyboard. <kbd>1</kbd> or <kbd>1 QZ</kbd> on a phone or remote
1048    /// control
1049    Numpad1,
1050    /// <kbd>2 ↓</kbd> on a keyboard. <kbd>2 ABC</kbd> on a phone or remote control
1051    Numpad2,
1052    /// <kbd>3 PgDn</kbd> on a keyboard. <kbd>3 DEF</kbd> on a phone or remote control
1053    Numpad3,
1054    /// <kbd>4 ←</kbd> on a keyboard. <kbd>4 GHI</kbd> on a phone or remote control
1055    Numpad4,
1056    /// <kbd>5</kbd> on a keyboard. <kbd>5 JKL</kbd> on a phone or remote control
1057    Numpad5,
1058    /// <kbd>6 →</kbd> on a keyboard. <kbd>6 MNO</kbd> on a phone or remote control
1059    Numpad6,
1060    /// <kbd>7 Home</kbd> on a keyboard. <kbd>7 PQRS</kbd> or <kbd>7 PRS</kbd> on a phone
1061    /// or remote control
1062    Numpad7,
1063    /// <kbd>8 ↑</kbd> on a keyboard. <kbd>8 TUV</kbd> on a phone or remote control
1064    Numpad8,
1065    /// <kbd>9 PgUp</kbd> on a keyboard. <kbd>9 WXYZ</kbd> or <kbd>9 WXY</kbd> on a phone
1066    /// or remote control
1067    Numpad9,
1068    /// <kbd>+</kbd>
1069    NumpadAdd,
1070    /// Found on the Microsoft Natural Keyboard.
1071    NumpadBackspace,
1072    /// <kbd>C</kbd> or <kbd>A</kbd> (All Clear). Also for use with numpads that have a
1073    /// <kbd>Clear</kbd> key that is separate from the <kbd>NumLock</kbd> key. On the Mac, the
1074    /// numpad <kbd>Clear</kbd> key is encoded as [`NumLock`].
1075    ///
1076    /// [`NumLock`]: Self::NumLock
1077    NumpadClear,
1078    /// <kbd>C</kbd> (Clear Entry)
1079    NumpadClearEntry,
1080    /// <kbd>,</kbd> (thousands separator). For locales where the thousands separator
1081    /// is a "." (e.g., Brazil), this key may generate a <kbd>.</kbd>.
1082    NumpadComma,
1083    /// <kbd>. Del</kbd>. For locales where the decimal separator is "," (e.g.,
1084    /// Brazil), this key may generate a <kbd>,</kbd>.
1085    NumpadDecimal,
1086    /// <kbd>/</kbd>
1087    NumpadDivide,
1088    NumpadEnter,
1089    /// <kbd>=</kbd>
1090    NumpadEqual,
1091    /// <kbd>#</kbd> on a phone or remote control device. This key is typically found
1092    /// below the <kbd>9</kbd> key and to the right of the <kbd>0</kbd> key.
1093    NumpadHash,
1094    /// <kbd>M</kbd> Add current entry to the value stored in memory.
1095    NumpadMemoryAdd,
1096    /// <kbd>M</kbd> Clear the value stored in memory.
1097    NumpadMemoryClear,
1098    /// <kbd>M</kbd> Replace the current entry with the value stored in memory.
1099    NumpadMemoryRecall,
1100    /// <kbd>M</kbd> Replace the value stored in memory with the current entry.
1101    NumpadMemoryStore,
1102    /// <kbd>M</kbd> Subtract current entry from the value stored in memory.
1103    NumpadMemorySubtract,
1104    /// <kbd>*</kbd> on a keyboard. For use with numpads that provide mathematical
1105    /// operations (<kbd>+</kbd>, <kbd>-</kbd> <kbd>*</kbd> and <kbd>/</kbd>).
1106    ///
1107    /// Use `NumpadStar` for the <kbd>*</kbd> key on phones and remote controls.
1108    NumpadMultiply,
1109    /// <kbd>(</kbd> Found on the Microsoft Natural Keyboard.
1110    NumpadParenLeft,
1111    /// <kbd>)</kbd> Found on the Microsoft Natural Keyboard.
1112    NumpadParenRight,
1113    /// <kbd>*</kbd> on a phone or remote control device.
1114    ///
1115    /// This key is typically found below the <kbd>7</kbd> key and to the left of
1116    /// the <kbd>0</kbd> key.
1117    ///
1118    /// Use <kbd>"NumpadMultiply"</kbd> for the <kbd>*</kbd> key on
1119    /// numeric keypads.
1120    NumpadStar,
1121    /// <kbd>-</kbd>
1122    NumpadSubtract,
1123    /// <kbd>Esc</kbd> or <kbd>⎋</kbd>
1124    Escape,
1125    /// <kbd>Fn</kbd> This is typically a hardware key that does not generate a separate code.
1126    Fn,
1127    /// <kbd>FLock</kbd> or <kbd>FnLock</kbd>. Function Lock key. Found on the Microsoft
1128    /// Natural Keyboard.
1129    FnLock,
1130    /// <kbd>PrtScr SysRq</kbd> or <kbd>Print Screen</kbd>
1131    PrintScreen,
1132    /// <kbd>Scroll Lock</kbd>
1133    ScrollLock,
1134    /// <kbd>Pause Break</kbd>
1135    Pause,
1136    /// Some laptops place this key to the left of the <kbd>↑</kbd> key.
1137    ///
1138    /// This also the "back" button (triangle) on Android.
1139    BrowserBack,
1140    BrowserFavorites,
1141    /// Some laptops place this key to the right of the <kbd>↑</kbd> key.
1142    BrowserForward,
1143    /// The "home" button on Android.
1144    BrowserHome,
1145    BrowserRefresh,
1146    BrowserSearch,
1147    BrowserStop,
1148    /// <kbd>Eject</kbd> or <kbd>⏏</kbd>. This key is placed in the function section on some Apple
1149    /// keyboards.
1150    Eject,
1151    /// Sometimes labelled <kbd>My Computer</kbd> on the keyboard
1152    LaunchApp1,
1153    /// Sometimes labelled <kbd>Calculator</kbd> on the keyboard
1154    LaunchApp2,
1155    LaunchMail,
1156    MediaPlayPause,
1157    MediaSelect,
1158    MediaStop,
1159    MediaTrackNext,
1160    MediaTrackPrevious,
1161    /// This key is placed in the function section on some Apple keyboards, replacing the
1162    /// <kbd>Eject</kbd> key.
1163    Power,
1164    Sleep,
1165    AudioVolumeDown,
1166    AudioVolumeMute,
1167    AudioVolumeUp,
1168    WakeUp,
1169    // Legacy modifier key. Also called "Super" in certain places.
1170    Meta,
1171    // Legacy modifier key.
1172    Hyper,
1173    Turbo,
1174    Abort,
1175    Resume,
1176    Suspend,
1177    /// Found on Sun’s USB keyboard.
1178    Again,
1179    /// Found on Sun’s USB keyboard.
1180    Copy,
1181    /// Found on Sun’s USB keyboard.
1182    Cut,
1183    /// Found on Sun’s USB keyboard.
1184    Find,
1185    /// Found on Sun’s USB keyboard.
1186    Open,
1187    /// Found on Sun’s USB keyboard.
1188    Paste,
1189    /// Found on Sun’s USB keyboard.
1190    Props,
1191    /// Found on Sun’s USB keyboard.
1192    Select,
1193    /// Found on Sun’s USB keyboard.
1194    Undo,
1195    /// Use for dedicated <kbd>ひらがな</kbd> key found on some Japanese word processing keyboards.
1196    Hiragana,
1197    /// Use for dedicated <kbd>カタカナ</kbd> key found on some Japanese word processing keyboards.
1198    Katakana,
1199    /// General-purpose function key.
1200    /// Usually found at the top of the keyboard.
1201    F1,
1202    /// General-purpose function key.
1203    /// Usually found at the top of the keyboard.
1204    F2,
1205    /// General-purpose function key.
1206    /// Usually found at the top of the keyboard.
1207    F3,
1208    /// General-purpose function key.
1209    /// Usually found at the top of the keyboard.
1210    F4,
1211    /// General-purpose function key.
1212    /// Usually found at the top of the keyboard.
1213    F5,
1214    /// General-purpose function key.
1215    /// Usually found at the top of the keyboard.
1216    F6,
1217    /// General-purpose function key.
1218    /// Usually found at the top of the keyboard.
1219    F7,
1220    /// General-purpose function key.
1221    /// Usually found at the top of the keyboard.
1222    F8,
1223    /// General-purpose function key.
1224    /// Usually found at the top of the keyboard.
1225    F9,
1226    /// General-purpose function key.
1227    /// Usually found at the top of the keyboard.
1228    F10,
1229    /// General-purpose function key.
1230    /// Usually found at the top of the keyboard.
1231    F11,
1232    /// General-purpose function key.
1233    /// Usually found at the top of the keyboard.
1234    F12,
1235    /// General-purpose function key.
1236    /// Usually found at the top of the keyboard.
1237    F13,
1238    /// General-purpose function key.
1239    /// Usually found at the top of the keyboard.
1240    F14,
1241    /// General-purpose function key.
1242    /// Usually found at the top of the keyboard.
1243    F15,
1244    /// General-purpose function key.
1245    /// Usually found at the top of the keyboard.
1246    F16,
1247    /// General-purpose function key.
1248    /// Usually found at the top of the keyboard.
1249    F17,
1250    /// General-purpose function key.
1251    /// Usually found at the top of the keyboard.
1252    F18,
1253    /// General-purpose function key.
1254    /// Usually found at the top of the keyboard.
1255    F19,
1256    /// General-purpose function key.
1257    /// Usually found at the top of the keyboard.
1258    F20,
1259    /// General-purpose function key.
1260    /// Usually found at the top of the keyboard.
1261    F21,
1262    /// General-purpose function key.
1263    /// Usually found at the top of the keyboard.
1264    F22,
1265    /// General-purpose function key.
1266    /// Usually found at the top of the keyboard.
1267    F23,
1268    /// General-purpose function key.
1269    /// Usually found at the top of the keyboard.
1270    F24,
1271    /// General-purpose function key.
1272    F25,
1273    /// General-purpose function key.
1274    F26,
1275    /// General-purpose function key.
1276    F27,
1277    /// General-purpose function key.
1278    F28,
1279    /// General-purpose function key.
1280    F29,
1281    /// General-purpose function key.
1282    F30,
1283    /// General-purpose function key.
1284    F31,
1285    /// General-purpose function key.
1286    F32,
1287    /// General-purpose function key.
1288    F33,
1289    /// General-purpose function key.
1290    F34,
1291    /// General-purpose function key.
1292    F35,
1293}
1294
1295/// Contains the platform-native physical key identifier.
1296///
1297/// The exact values vary from platform to platform (which is part of why this is a per-platform
1298/// enum), but the values are primarily tied to the key's physical location on the keyboard.
1299///
1300/// This enum is primarily used to store raw keycodes when Winit doesn't map a given native
1301/// physical key identifier to a meaningful [`Code`] variant. In the presence of identifiers we
1302/// haven't mapped for you yet, this lets you use use [`Code`] to:
1303///
1304/// - Correctly match key press and release events.
1305/// - On non-web platforms, support assigning keybinds to virtually any key through a UI.
1306#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1307pub enum NativeCode {
1308    /// An unidentified code.
1309    Unidentified,
1310    /// An Android "scancode".
1311    Android(u32),
1312    /// A macOS "scancode".
1313    MacOS(u16),
1314    /// A Windows "scancode".
1315    Windows(u16),
1316    /// An XKB "keycode".
1317    Xkb(u32),
1318}
1319
1320/// Represents the location of a physical key.
1321///
1322/// This type is a superset of [`Code`], including an [`Unidentified`][Self::Unidentified]
1323/// variant.
1324#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1325pub enum Physical {
1326    /// A known key code
1327    Code(Code),
1328    /// This variant is used when the key cannot be translated to a [`Code`]
1329    ///
1330    /// The native keycode is provided (if available) so you're able to more reliably match
1331    /// key-press and key-release events by hashing the [`Physical`] key. It is also possible to use
1332    /// this for keybinds for non-standard keys, but such keybinds are tied to a given platform.
1333    Unidentified(NativeCode),
1334}
1335
1336impl PartialEq<Code> for Physical {
1337    #[inline]
1338    fn eq(&self, rhs: &Code) -> bool {
1339        match self {
1340            Physical::Code(code) => code == rhs,
1341            Physical::Unidentified(_) => false,
1342        }
1343    }
1344}
1345
1346impl PartialEq<Physical> for Code {
1347    #[inline]
1348    fn eq(&self, rhs: &Physical) -> bool {
1349        rhs == self
1350    }
1351}
1352
1353impl PartialEq<NativeCode> for Physical {
1354    #[inline]
1355    fn eq(&self, rhs: &NativeCode) -> bool {
1356        match self {
1357            Physical::Unidentified(code) => code == rhs,
1358            Physical::Code(_) => false,
1359        }
1360    }
1361}
1362
1363impl PartialEq<Physical> for NativeCode {
1364    #[inline]
1365    fn eq(&self, rhs: &Physical) -> bool {
1366        rhs == self
1367    }
1368}