Skip to main content

tao/
keyboard.rs

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