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