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