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