bevy_input/
keyboard.rs

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