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