diff --git a/Cargo.toml b/Cargo.toml index 0ccbaadd..71b8fc65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ bitflags = "2" cfg_aliases = "0.2.1" cursor-icon = "1.1.0" dpi = { version = "0.1.2", path = "dpi" } +keyboard-types = "0.8.0" mint = "0.5.6" rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"] } serde = { version = "1", features = ["serde_derive"] } diff --git a/docs/ATTRIBUTION.md b/docs/ATTRIBUTION.md index 259a91d2..adf1e4fc 100644 --- a/docs/ATTRIBUTION.md +++ b/docs/ATTRIBUTION.md @@ -2,14 +2,6 @@ These images are used in the documentation of `winit`. -## keyboard_*.svg - -These files are a modified version of "[ANSI US QWERTY (Windows)](https://commons.wikimedia.org/wiki/File:ANSI_US_QWERTY_(Windows).svg)" -by [Tomiĉo] (https://commons.wikimedia.org/wiki/User:Tomi%C4%89o). It was -originally released under the [CC-BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/deed.en) -License. Minor modifications have been made by [John Nunley](https://github.com/notgull), -which have been released under the same license as a derivative work. - ## `coordinate-systems*` These files are created by [Mads Marquart](https://github.com/madsmtm) using diff --git a/docs/res/keyboard_left_shift_key.svg b/docs/res/keyboard_left_shift_key.svg deleted file mode 100644 index bae6f9af..00000000 --- a/docs/res/keyboard_left_shift_key.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/docs/res/keyboard_numpad_1_key.svg b/docs/res/keyboard_numpad_1_key.svg deleted file mode 100644 index d5957581..00000000 --- a/docs/res/keyboard_numpad_1_key.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/docs/res/keyboard_right_shift_key.svg b/docs/res/keyboard_right_shift_key.svg deleted file mode 100644 index dc016f05..00000000 --- a/docs/res/keyboard_right_shift_key.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/docs/res/keyboard_standard_1_key.svg b/docs/res/keyboard_standard_1_key.svg deleted file mode 100644 index 3520d550..00000000 --- a/docs/res/keyboard_standard_1_key.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/winit-core/Cargo.toml b/winit-core/Cargo.toml index bce82c98..b9606a9f 100644 --- a/winit-core/Cargo.toml +++ b/winit-core/Cargo.toml @@ -13,12 +13,20 @@ rust-version.workspace = true version = "0.0.0" [features] -serde = ["dep:serde", "cursor-icon/serde", "smol_str/serde", "dpi/serde", "bitflags/serde"] +serde = [ + "dep:serde", + "bitflags/serde", + "cursor-icon/serde", + "dpi/serde", + "keyboard-types/serde", + "smol_str/serde", +] [dependencies] bitflags.workspace = true cursor-icon.workspace = true dpi.workspace = true +keyboard-types.workspace = true rwh_06.workspace = true serde = { workspace = true, optional = true } smol_str.workspace = true diff --git a/winit-core/src/keyboard.rs b/winit-core/src/keyboard.rs index 22fbe294..01f82043 100644 --- a/winit-core/src/keyboard.rs +++ b/winit-core/src/keyboard.rs @@ -1,76 +1,7 @@ //! Types related to the keyboard. -#![cfg_attr(feature = "serde", allow(deprecated))] // https://github.com/serde-rs/serde/issues/2195 - -// This file contains a substantial portion of the UI Events Specification by the W3C. In -// particular, the variant names within `Key` and `KeyCode` and their documentation are modified -// versions of contents of the aforementioned specification. -// -// The original documents are: -// -// ### For `Key` -// UI Events KeyboardEvent key Values -// https://www.w3.org/TR/2017/CR-uievents-key-20170601/ -// Copyright © 2017 W3C® (MIT, ERCIM, Keio, Beihang). -// -// ### For `KeyCode` -// UI Events KeyboardEvent code Values -// https://www.w3.org/TR/2017/CR-uievents-code-20170601/ -// Copyright © 2017 W3C® (MIT, ERCIM, Keio, Beihang). -// -// These documents were used under the terms of the following license. This W3C license as well as -// the W3C short notice apply to the `Key` and `KeyCode` enums and their variants and the -// documentation attached to their variants. - -// --------- BEGINNING OF W3C LICENSE -------------------------------------------------------------- -// -// License -// -// By obtaining and/or copying this work, you (the licensee) agree that you have read, understood, -// and will comply with the following terms and conditions. -// -// Permission to copy, modify, and distribute this work, with or without modification, for any -// purpose and without fee or royalty is hereby granted, provided that you include the following on -// ALL copies of the work or portions thereof, including modifications: -// -// - The full text of this NOTICE in a location viewable to users of the redistributed or derivative -// work. -// - Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none -// exist, the W3C Software and Document Short Notice should be included. -// - Notice of any changes or modifications, through a copyright statement on the new code or -// document such as "This software or document includes material copied from or derived from -// [title and URI of the W3C document]. Copyright © [YEAR] W3C® (MIT, ERCIM, Keio, Beihang)." -// -// Disclaimers -// -// THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR -// ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD -// PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. -// -// COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES -// ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT. -// -// The name and trademarks of copyright holders may NOT be used in advertising or publicity -// pertaining to the work without specific, written prior permission. Title to copyright in this -// work will at all times remain with copyright holders. -// -// --------- END OF W3C LICENSE -------------------------------------------------------------------- - -// --------- BEGINNING OF W3C SHORT NOTICE --------------------------------------------------------- -// -// winit: https://github.com/rust-windowing/winit -// -// Copyright © 2021 World Wide Web Consortium, (Massachusetts Institute of Technology, European -// Research Consortium for Informatics and Mathematics, Keio University, Beihang). All Rights -// Reserved. This work is distributed under the W3C® Software License [1] in the hope that it will -// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// [1] http://www.w3.org/Consortium/Legal/copyright-software -// -// --------- END OF W3C SHORT NOTICE --------------------------------------------------------------- use bitflags::bitflags; +pub use keyboard_types::{Code as KeyCode, Location as KeyLocation, NamedKey}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; pub use smol_str::SmolStr; @@ -219,8 +150,8 @@ impl PartialEq for NativeKey { /// Represents the location of a physical key. /// -/// This type is a superset of [`KeyCode`], including an [`Unidentified`][Self::Unidentified] -/// variant. +/// Winit will not emit [`KeyCode::Unidentified`] when it cannot recognize the key, instead it will +/// emit [`PhysicalKey::Unidentified`] with additional data about the key. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum PhysicalKey { @@ -241,6 +172,16 @@ impl From for PhysicalKey { } } +impl From for KeyCode { + #[inline] + fn from(key: PhysicalKey) -> Self { + match key { + PhysicalKey::Code(code) => code, + PhysicalKey::Unidentified(_) => KeyCode::Unidentified, + } + } +} + impl From for PhysicalKey { #[inline] fn from(code: NativeKeyCode) -> Self { @@ -282,1173 +223,6 @@ impl PartialEq for NativeKeyCode { } } -/// Code representing the location of a physical key -/// -/// This conforms to the UI Events Specification's [`KeyboardEvent.code`]. -/// -/// [`KeyboardEvent.code`]: https://w3c.github.io/uievents-code/#code-value-tables -#[non_exhaustive] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum KeyCode { - /// ` on a US keyboard. This is also called a backtick or grave. - /// This is the 半角/全角/漢字 - /// (hankaku/zenkaku/kanji) key on Japanese keyboards - Backquote, - /// Used for both the US \\ (on the 101-key layout) and also for the key - /// located between the " and Enter keys on row C of the 102-, - /// 104- and 106-key layouts. - /// Labeled # on a UK (102) keyboard. - Backslash, - /// [ on a US keyboard. - BracketLeft, - /// ] on a US keyboard. - BracketRight, - /// , on a US keyboard. - Comma, - /// 0 on a US keyboard. - Digit0, - /// 1 on a US keyboard. - Digit1, - /// 2 on a US keyboard. - Digit2, - /// 3 on a US keyboard. - Digit3, - /// 4 on a US keyboard. - Digit4, - /// 5 on a US keyboard. - Digit5, - /// 6 on a US keyboard. - Digit6, - /// 7 on a US keyboard. - Digit7, - /// 8 on a US keyboard. - Digit8, - /// 9 on a US keyboard. - Digit9, - /// = on a US keyboard. - Equal, - /// Located between the left Shift and Z keys. - /// Labeled \\ on a UK keyboard. - IntlBackslash, - /// Located between the / and right Shift keys. - /// Labeled \\ (ro) on a Japanese keyboard. - IntlRo, - /// Located between the = and Backspace keys. - /// Labeled ¥ (yen) on a Japanese keyboard. \\ on a - /// Russian keyboard. - IntlYen, - /// a on a US keyboard. - /// Labeled q on an AZERTY (e.g., French) keyboard. - KeyA, - /// b on a US keyboard. - KeyB, - /// c on a US keyboard. - KeyC, - /// d on a US keyboard. - KeyD, - /// e on a US keyboard. - KeyE, - /// f on a US keyboard. - KeyF, - /// g on a US keyboard. - KeyG, - /// h on a US keyboard. - KeyH, - /// i on a US keyboard. - KeyI, - /// j on a US keyboard. - KeyJ, - /// k on a US keyboard. - KeyK, - /// l on a US keyboard. - KeyL, - /// m on a US keyboard. - KeyM, - /// n on a US keyboard. - KeyN, - /// o on a US keyboard. - KeyO, - /// p on a US keyboard. - KeyP, - /// q on a US keyboard. - /// Labeled a on an AZERTY (e.g., French) keyboard. - KeyQ, - /// r on a US keyboard. - KeyR, - /// s on a US keyboard. - KeyS, - /// t on a US keyboard. - KeyT, - /// u on a US keyboard. - KeyU, - /// v on a US keyboard. - KeyV, - /// w on a US keyboard. - /// Labeled z on an AZERTY (e.g., French) keyboard. - KeyW, - /// x on a US keyboard. - KeyX, - /// y on a US keyboard. - /// Labeled z on a QWERTZ (e.g., German) keyboard. - KeyY, - /// z on a US keyboard. - /// Labeled w on an AZERTY (e.g., French) keyboard, and y on a - /// QWERTZ (e.g., German) keyboard. - KeyZ, - /// - on a US keyboard. - Minus, - /// . on a US keyboard. - Period, - /// ' on a US keyboard. - Quote, - /// ; on a US keyboard. - Semicolon, - /// / on a US keyboard. - Slash, - /// Alt, Option, or . - AltLeft, - /// Alt, Option, or . - /// This is labeled AltGr on many keyboard layouts. - AltRight, - /// Backspace or . - /// Labeled Delete on Apple keyboards. - Backspace, - /// CapsLock or - CapsLock, - /// The application context menu key, which is typically found between the right - /// Meta key and the right Control key. - ContextMenu, - /// Control or - ControlLeft, - /// Control or - ControlRight, - /// Enter or . Labeled Return on Apple keyboards. - Enter, - /// The Windows, , Command, or other OS symbol key. - MetaLeft, - /// The Windows, , Command, or other OS symbol key. - MetaRight, - /// Shift or - ShiftLeft, - /// Shift or - ShiftRight, - ///   (space) - Space, - /// Tab or - Tab, - /// Japanese: (henkan) - Convert, - /// Japanese: カタカナ/ひらがな/ローマ字 - /// (katakana/hiragana/romaji) - KanaMode, - /// Korean: HangulMode 한/영 (han/yeong) - /// - /// Japanese (Mac keyboard): (kana) - Lang1, - /// Korean: Hanja (hanja) - /// - /// Japanese (Mac keyboard): (eisu) - Lang2, - /// Japanese (word-processing keyboard): Katakana - Lang3, - /// Japanese (word-processing keyboard): Hiragana - Lang4, - /// Japanese (word-processing keyboard): Zenkaku/Hankaku - Lang5, - /// Japanese: 無変換 (muhenkan) - NonConvert, - /// . The forward delete key. - /// Note that on Apple keyboards, the key labelled Delete on the main part of - /// the keyboard is encoded as [`Backspace`]. - /// - /// [`Backspace`]: Self::Backspace - Delete, - /// Page Down, End, or - End, - /// Help. Not present on standard PC keyboards. - Help, - /// Home or - Home, - /// Insert or Ins. Not present on Apple keyboards. - Insert, - /// Page Down, PgDn, or - PageDown, - /// Page Up, PgUp, or - PageUp, - /// - ArrowDown, - /// - ArrowLeft, - /// - ArrowRight, - /// - ArrowUp, - /// On the Mac, this is used for the numpad Clear key. - NumLock, - /// 0 Ins on a keyboard. 0 on a phone or remote control - Numpad0, - /// 1 End on a keyboard. 1 or 1 QZ on a phone or remote - /// control - Numpad1, - /// 2 ↓ on a keyboard. 2 ABC on a phone or remote control - Numpad2, - /// 3 PgDn on a keyboard. 3 DEF on a phone or remote control - Numpad3, - /// 4 ← on a keyboard. 4 GHI on a phone or remote control - Numpad4, - /// 5 on a keyboard. 5 JKL on a phone or remote control - Numpad5, - /// 6 → on a keyboard. 6 MNO on a phone or remote control - Numpad6, - /// 7 Home on a keyboard. 7 PQRS or 7 PRS on a phone - /// or remote control - Numpad7, - /// 8 ↑ on a keyboard. 8 TUV on a phone or remote control - Numpad8, - /// 9 PgUp on a keyboard. 9 WXYZ or 9 WXY on a phone - /// or remote control - Numpad9, - /// + - NumpadAdd, - /// Found on the Microsoft Natural Keyboard. - NumpadBackspace, - /// C or A (All Clear). Also for use with numpads that have a - /// Clear key that is separate from the NumLock key. On the Mac, the - /// numpad Clear key is encoded as [`NumLock`]. - /// - /// [`NumLock`]: Self::NumLock - NumpadClear, - /// C (Clear Entry) - NumpadClearEntry, - /// , (thousands separator). For locales where the thousands separator - /// is a "." (e.g., Brazil), this key may generate a .. - NumpadComma, - /// . Del. For locales where the decimal separator is "," (e.g., - /// Brazil), this key may generate a ,. - NumpadDecimal, - /// / - NumpadDivide, - NumpadEnter, - /// = - NumpadEqual, - /// # on a phone or remote control device. This key is typically found - /// below the 9 key and to the right of the 0 key. - NumpadHash, - /// M Add current entry to the value stored in memory. - NumpadMemoryAdd, - /// M Clear the value stored in memory. - NumpadMemoryClear, - /// M Replace the current entry with the value stored in memory. - NumpadMemoryRecall, - /// M Replace the value stored in memory with the current entry. - NumpadMemoryStore, - /// M Subtract current entry from the value stored in memory. - NumpadMemorySubtract, - /// * on a keyboard. For use with numpads that provide mathematical - /// operations (+, - * and /). - /// - /// Use `NumpadStar` for the * key on phones and remote controls. - NumpadMultiply, - /// ( Found on the Microsoft Natural Keyboard. - NumpadParenLeft, - /// ) Found on the Microsoft Natural Keyboard. - NumpadParenRight, - /// * on a phone or remote control device. - /// - /// This key is typically found below the 7 key and to the left of - /// the 0 key. - /// - /// Use "NumpadMultiply" for the * key on - /// numeric keypads. - NumpadStar, - /// - - NumpadSubtract, - /// Esc or - Escape, - /// Fn This is typically a hardware key that does not generate a separate code. - Fn, - /// FLock or FnLock. Function Lock key. Found on the Microsoft - /// Natural Keyboard. - FnLock, - /// PrtScr SysRq or Print Screen - PrintScreen, - /// Scroll Lock - ScrollLock, - /// Pause Break - Pause, - /// Some laptops place this key to the left of the key. - /// - /// This also the "back" button (triangle) on Android. - BrowserBack, - BrowserFavorites, - /// Some laptops place this key to the right of the key. - BrowserForward, - /// The "home" button on Android. - BrowserHome, - BrowserRefresh, - BrowserSearch, - BrowserStop, - /// Eject or . This key is placed in the function section on some Apple - /// keyboards. - Eject, - /// Sometimes labelled My Computer on the keyboard - LaunchApp1, - /// Sometimes labelled Calculator on the keyboard - LaunchApp2, - LaunchMail, - MediaPlayPause, - MediaSelect, - MediaStop, - MediaTrackNext, - MediaTrackPrevious, - /// This key is placed in the function section on some Apple keyboards, replacing the - /// Eject key. - Power, - Sleep, - AudioVolumeDown, - AudioVolumeMute, - AudioVolumeUp, - WakeUp, - // Legacy modifier key. - #[deprecated = "marked as legacy in the spec, use Meta instead"] - Super, - // Legacy modifier key. - #[deprecated = "marked as legacy in the spec, use Meta instead"] - Hyper, - Turbo, - Abort, - Resume, - Suspend, - /// Found on Sun’s USB keyboard. - Again, - /// Found on Sun’s USB keyboard. - Copy, - /// Found on Sun’s USB keyboard. - Cut, - /// Found on Sun’s USB keyboard. - Find, - /// Found on Sun’s USB keyboard. - Open, - /// Found on Sun’s USB keyboard. - Paste, - /// Found on Sun’s USB keyboard. - Props, - /// Found on Sun’s USB keyboard. - Select, - /// Found on Sun’s USB keyboard. - Undo, - /// Use for dedicated ひらがな key found on some Japanese word processing keyboards. - Hiragana, - /// Use for dedicated カタカナ key found on some Japanese word processing keyboards. - Katakana, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F1, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F2, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F3, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F4, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F5, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F6, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F7, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F8, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F9, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F10, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F11, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F12, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F13, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F14, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F15, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F16, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F17, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F18, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F19, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F20, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F21, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F22, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F23, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F24, - /// General-purpose function key. - F25, - /// General-purpose function key. - F26, - /// General-purpose function key. - F27, - /// General-purpose function key. - F28, - /// General-purpose function key. - F29, - /// General-purpose function key. - F30, - /// General-purpose function key. - F31, - /// General-purpose function key. - F32, - /// General-purpose function key. - F33, - /// General-purpose function key. - F34, - /// General-purpose function key. - F35, -} - -/// A [`Key::Named`] value -/// -/// This conforms to the UI Events Specification's [`KeyboardEvent.key`]. -/// -/// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/ -#[non_exhaustive] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum NamedKey { - /// The `Alt` (Alternative) key. - /// - /// This key enables the alternate modifier function for interpreting concurrent or subsequent - /// keyboard input. This key value is also used for the Apple Option key. - Alt, - /// The Alternate Graphics (AltGr or AltGraph) key. - /// - /// This key is used enable the ISO Level 3 shift modifier (the standard `Shift` key is the - /// level 2 modifier). - AltGraph, - /// The `Caps Lock` (Capital) key. - /// - /// Toggle capital character lock function for interpreting subsequent keyboard input event. - CapsLock, - /// The `Control` or `Ctrl` key. - /// - /// Used to enable control modifier function for interpreting concurrent or subsequent keyboard - /// input. - Control, - /// The Function switch `Fn` key. Activating this key simultaneously with another key changes - /// that key’s value to an alternate character or function. This key is often handled directly - /// in the keyboard hardware and does not usually generate key events. - Fn, - /// The Function-Lock (`FnLock` or `F-Lock`) key. Activating this key switches the mode of the - /// keyboard to changes some keys' values to an alternate character or function. This key is - /// often handled directly in the keyboard hardware and does not usually generate key events. - FnLock, - /// The `NumLock` or Number Lock key. Used to toggle numpad mode function for interpreting - /// subsequent keyboard input. - NumLock, - /// Toggle between scrolling and cursor movement modes. - ScrollLock, - /// Used to enable shift modifier function for interpreting concurrent or subsequent keyboard - /// input. - Shift, - /// The Symbol modifier key (used on some virtual keyboards). - Symbol, - SymbolLock, - // Legacy modifier key. - #[deprecated = "marked as legacy in the spec, use Meta instead"] - Super, - // Legacy modifier key. - #[deprecated = "marked as legacy in the spec, use Meta instead"] - Hyper, - /// Used to enable "meta" modifier function for interpreting concurrent or subsequent keyboard - /// input. This key value is used for the "Windows Logo" key and the Apple `Command` or `⌘` - /// key. - Meta, - /// The `Enter` or `↵` key. Used to activate current selection or accept current input. This - /// key value is also used for the `Return` (Macintosh numpad) key. This key value is also - /// used for the Android `KEYCODE_DPAD_CENTER`. - Enter, - /// The Horizontal Tabulation `Tab` key. - Tab, - /// Navigate or traverse downward. (`KEYCODE_DPAD_DOWN`) - ArrowDown, - /// Navigate or traverse leftward. (`KEYCODE_DPAD_LEFT`) - ArrowLeft, - /// Navigate or traverse rightward. (`KEYCODE_DPAD_RIGHT`) - ArrowRight, - /// Navigate or traverse upward. (`KEYCODE_DPAD_UP`) - ArrowUp, - /// The End key, used with keyboard entry to go to the end of content (`KEYCODE_MOVE_END`). - End, - /// The Home key, used with keyboard entry, to go to start of content (`KEYCODE_MOVE_HOME`). - /// For the mobile phone `Home` key (which goes to the phone’s main screen), use [`GoHome`]. - /// - /// [`GoHome`]: Self::GoHome - Home, - /// Scroll down or display next page of content. - PageDown, - /// Scroll up or display previous page of content. - PageUp, - /// Used to remove the character to the left of the cursor. This key value is also used for - /// the key labeled `Delete` on MacOS keyboards. - Backspace, - /// Remove the currently selected input. - Clear, - /// Copy the current selection. (`APPCOMMAND_COPY`) - Copy, - /// The Cursor Select key. - CrSel, - /// Cut the current selection. (`APPCOMMAND_CUT`) - Cut, - /// Used to delete the character to the right of the cursor. This key value is also used for - /// the key labeled `Delete` on MacOS keyboards when `Fn` is active. - Delete, - /// The Erase to End of Field key. This key deletes all characters from the current cursor - /// position to the end of the current field. - EraseEof, - /// The Extend Selection (Exsel) key. - ExSel, - /// Toggle between text modes for insertion or overtyping. - /// (`KEYCODE_INSERT`) - Insert, - /// The Paste key. (`APPCOMMAND_PASTE`) - Paste, - /// Redo the last action. (`APPCOMMAND_REDO`) - Redo, - /// Undo the last action. (`APPCOMMAND_UNDO`) - Undo, - /// The Accept (Commit, OK) key. Accept current option or input method sequence conversion. - Accept, - /// Redo or repeat an action. - Again, - /// The Attention (Attn) key. - Attn, - Cancel, - /// Show the application’s context menu. - /// This key is commonly found between the right `Meta` key and the right `Control` key. - ContextMenu, - /// The `Esc` key. This key was originally used to initiate an escape sequence, but is - /// now more generally used to exit or "escape" the current context, such as closing a dialog - /// or exiting full screen mode. - Escape, - Execute, - /// Open the Find dialog. (`APPCOMMAND_FIND`) - Find, - /// Open a help dialog or toggle display of help information. (`APPCOMMAND_HELP`, - /// `KEYCODE_HELP`) - Help, - /// Pause the current state or application (as appropriate). - /// - /// Note: Do not use this value for the `Pause` button on media controllers. Use `"MediaPause"` - /// instead. - Pause, - /// Play or resume the current state or application (as appropriate). - /// - /// Note: Do not use this value for the `Play` button on media controllers. Use `"MediaPlay"` - /// instead. - Play, - /// The properties (Props) key. - Props, - Select, - /// The ZoomIn key. (`KEYCODE_ZOOM_IN`) - ZoomIn, - /// The ZoomOut key. (`KEYCODE_ZOOM_OUT`) - ZoomOut, - /// The Brightness Down key. Typically controls the display brightness. - /// (`KEYCODE_BRIGHTNESS_DOWN`) - BrightnessDown, - /// The Brightness Up key. Typically controls the display brightness. (`KEYCODE_BRIGHTNESS_UP`) - BrightnessUp, - /// Toggle removable media to eject (open) and insert (close) state. (`KEYCODE_MEDIA_EJECT`) - Eject, - LogOff, - /// Toggle power state. (`KEYCODE_POWER`) - /// Note: Note: Some devices might not expose this key to the operating environment. - Power, - /// The `PowerOff` key. Sometime called `PowerDown`. - PowerOff, - /// Initiate print-screen function. - PrintScreen, - /// The Hibernate key. This key saves the current state of the computer to disk so that it can - /// be restored. The computer will then shutdown. - Hibernate, - /// The Standby key. This key turns off the display and places the computer into a low-power - /// mode without completely shutting down. It is sometimes labelled `Suspend` or `Sleep` key. - /// (`KEYCODE_SLEEP`) - Standby, - /// The WakeUp key. (`KEYCODE_WAKEUP`) - WakeUp, - /// Initiate the multi-candidate mode. - AllCandidates, - Alphanumeric, - /// Initiate the Code Input mode to allow characters to be entered by - /// their code points. - CodeInput, - /// The Compose key, also known as "Multi_key" on the X Window System. This key acts in a - /// manner similar to a dead key, triggering a mode where subsequent key presses are combined - /// to produce a different character. - Compose, - /// Convert the current input method sequence. - Convert, - /// The Final Mode `Final` key used on some Asian keyboards, to enable the final mode for IMEs. - FinalMode, - /// Switch to the first character group. (ISO/IEC 9995) - GroupFirst, - /// Switch to the last character group. (ISO/IEC 9995) - GroupLast, - /// Switch to the next character group. (ISO/IEC 9995) - GroupNext, - /// Switch to the previous character group. (ISO/IEC 9995) - GroupPrevious, - /// Toggle between or cycle through input modes of IMEs. - ModeChange, - NextCandidate, - /// Accept current input method sequence without - /// conversion in IMEs. - NonConvert, - PreviousCandidate, - Process, - SingleCandidate, - /// Toggle between Hangul and English modes. - HangulMode, - HanjaMode, - JunjaMode, - /// The Eisu key. This key may close the IME, but its purpose is defined by the current IME. - /// (`KEYCODE_EISU`) - Eisu, - /// The (Half-Width) Characters key. - Hankaku, - /// The Hiragana (Japanese Kana characters) key. - Hiragana, - /// The Hiragana/Katakana toggle key. (`KEYCODE_KATAKANA_HIRAGANA`) - HiraganaKatakana, - /// The Kana Mode (Kana Lock) key. This key is used to enter hiragana mode (typically from - /// romaji mode). - KanaMode, - /// The Kanji (Japanese name for ideographic characters of Chinese origin) Mode key. This key - /// is typically used to switch to a hiragana keyboard for the purpose of converting input - /// into kanji. (`KEYCODE_KANA`) - KanjiMode, - /// The Katakana (Japanese Kana characters) key. - Katakana, - /// The Roman characters function key. - Romaji, - /// The Zenkaku (Full-Width) Characters key. - Zenkaku, - /// The Zenkaku/Hankaku (full-width/half-width) toggle key. (`KEYCODE_ZENKAKU_HANKAKU`) - ZenkakuHankaku, - /// General purpose virtual function key, as index 1. - Soft1, - /// General purpose virtual function key, as index 2. - Soft2, - /// General purpose virtual function key, as index 3. - Soft3, - /// General purpose virtual function key, as index 4. - Soft4, - /// Select next (numerically or logically) lower channel. (`APPCOMMAND_MEDIA_CHANNEL_DOWN`, - /// `KEYCODE_CHANNEL_DOWN`) - ChannelDown, - /// Select next (numerically or logically) higher channel. (`APPCOMMAND_MEDIA_CHANNEL_UP`, - /// `KEYCODE_CHANNEL_UP`) - ChannelUp, - /// Close the current document or message (Note: This doesn’t close the application). - /// (`APPCOMMAND_CLOSE`) - Close, - /// Open an editor to forward the current message. (`APPCOMMAND_FORWARD_MAIL`) - MailForward, - /// Open an editor to reply to the current message. (`APPCOMMAND_REPLY_TO_MAIL`) - MailReply, - /// Send the current message. (`APPCOMMAND_SEND_MAIL`) - MailSend, - /// Close the current media, for example to close a CD or DVD tray. (`KEYCODE_MEDIA_CLOSE`) - MediaClose, - /// Initiate or continue forward playback at faster than normal speed, or increase speed if - /// already fast forwarding. (`APPCOMMAND_MEDIA_FAST_FORWARD`, `KEYCODE_MEDIA_FAST_FORWARD`) - MediaFastForward, - /// Pause the currently playing media. (`APPCOMMAND_MEDIA_PAUSE`, `KEYCODE_MEDIA_PAUSE`) - /// - /// Note: Media controller devices should use this value rather than `"Pause"` for their pause - /// keys. - MediaPause, - /// Initiate or continue media playback at normal speed, if not currently playing at normal - /// speed. (`APPCOMMAND_MEDIA_PLAY`, `KEYCODE_MEDIA_PLAY`) - MediaPlay, - /// Toggle media between play and pause states. (`APPCOMMAND_MEDIA_PLAY_PAUSE`, - /// `KEYCODE_MEDIA_PLAY_PAUSE`) - MediaPlayPause, - /// Initiate or resume recording of currently selected media. (`APPCOMMAND_MEDIA_RECORD`, - /// `KEYCODE_MEDIA_RECORD`) - MediaRecord, - /// Initiate or continue reverse playback at faster than normal speed, or increase speed if - /// already rewinding. (`APPCOMMAND_MEDIA_REWIND`, `KEYCODE_MEDIA_REWIND`) - MediaRewind, - /// Stop media playing, pausing, forwarding, rewinding, or recording, if not already stopped. - /// (`APPCOMMAND_MEDIA_STOP`, `KEYCODE_MEDIA_STOP`) - MediaStop, - /// Seek to next media or program track. (`APPCOMMAND_MEDIA_NEXTTRACK`, `KEYCODE_MEDIA_NEXT`) - MediaTrackNext, - /// Seek to previous media or program track. (`APPCOMMAND_MEDIA_PREVIOUSTRACK`, - /// `KEYCODE_MEDIA_PREVIOUS`) - MediaTrackPrevious, - /// Open a new document or message. (`APPCOMMAND_NEW`) - New, - /// Open an existing document or message. (`APPCOMMAND_OPEN`) - Open, - /// Print the current document or message. (`APPCOMMAND_PRINT`) - Print, - /// Save the current document or message. (`APPCOMMAND_SAVE`) - Save, - /// Spellcheck the current document or selection. (`APPCOMMAND_SPELL_CHECK`) - SpellCheck, - /// The `11` key found on media numpads that - /// have buttons from `1` ... `12`. - Key11, - /// The `12` key found on media numpads that - /// have buttons from `1` ... `12`. - Key12, - /// Adjust audio balance leftward. (`VK_AUDIO_BALANCE_LEFT`) - AudioBalanceLeft, - /// Adjust audio balance rightward. (`VK_AUDIO_BALANCE_RIGHT`) - AudioBalanceRight, - /// Decrease audio bass boost or cycle down through bass boost states. (`APPCOMMAND_BASS_DOWN`, - /// `VK_BASS_BOOST_DOWN`) - AudioBassBoostDown, - /// Toggle bass boost on/off. (`APPCOMMAND_BASS_BOOST`) - AudioBassBoostToggle, - /// Increase audio bass boost or cycle up through bass boost states. (`APPCOMMAND_BASS_UP`, - /// `VK_BASS_BOOST_UP`) - AudioBassBoostUp, - /// Adjust audio fader towards front. (`VK_FADER_FRONT`) - AudioFaderFront, - /// Adjust audio fader towards rear. (`VK_FADER_REAR`) - AudioFaderRear, - /// Advance surround audio mode to next available mode. (`VK_SURROUND_MODE_NEXT`) - AudioSurroundModeNext, - /// Decrease treble. (`APPCOMMAND_TREBLE_DOWN`) - AudioTrebleDown, - /// Increase treble. (`APPCOMMAND_TREBLE_UP`) - AudioTrebleUp, - /// Decrease audio volume. (`APPCOMMAND_VOLUME_DOWN`, `KEYCODE_VOLUME_DOWN`) - AudioVolumeDown, - /// Increase audio volume. (`APPCOMMAND_VOLUME_UP`, `KEYCODE_VOLUME_UP`) - AudioVolumeUp, - /// Toggle between muted state and prior volume level. (`APPCOMMAND_VOLUME_MUTE`, - /// `KEYCODE_VOLUME_MUTE`) - AudioVolumeMute, - /// Toggle the microphone on/off. (`APPCOMMAND_MIC_ON_OFF_TOGGLE`) - MicrophoneToggle, - /// Decrease microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_DOWN`) - MicrophoneVolumeDown, - /// Increase microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_UP`) - MicrophoneVolumeUp, - /// Mute the microphone. (`APPCOMMAND_MICROPHONE_VOLUME_MUTE`, `KEYCODE_MUTE`) - MicrophoneVolumeMute, - /// Show correction list when a word is incorrectly identified. (`APPCOMMAND_CORRECTION_LIST`) - SpeechCorrectionList, - /// Toggle between dictation mode and command/control mode. - /// (`APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE`) - SpeechInputToggle, - /// The first generic "LaunchApplication" key. This is commonly associated with launching "My - /// Computer", and may have a computer symbol on the key. (`APPCOMMAND_LAUNCH_APP1`) - LaunchApplication1, - /// The second generic "LaunchApplication" key. This is commonly associated with launching - /// "Calculator", and may have a calculator symbol on the key. (`APPCOMMAND_LAUNCH_APP2`, - /// `KEYCODE_CALCULATOR`) - LaunchApplication2, - /// The "Calendar" key. (`KEYCODE_CALENDAR`) - LaunchCalendar, - /// The "Contacts" key. (`KEYCODE_CONTACTS`) - LaunchContacts, - /// The "Mail" key. (`APPCOMMAND_LAUNCH_MAIL`) - LaunchMail, - /// The "Media Player" key. (`APPCOMMAND_LAUNCH_MEDIA_SELECT`) - LaunchMediaPlayer, - LaunchMusicPlayer, - LaunchPhone, - LaunchScreenSaver, - LaunchSpreadsheet, - LaunchWebBrowser, - LaunchWebCam, - LaunchWordProcessor, - /// Navigate to previous content or page in current history. (`APPCOMMAND_BROWSER_BACKWARD`) - BrowserBack, - /// Open the list of browser favorites. (`APPCOMMAND_BROWSER_FAVORITES`) - BrowserFavorites, - /// Navigate to next content or page in current history. (`APPCOMMAND_BROWSER_FORWARD`) - BrowserForward, - /// Go to the user’s preferred home page. (`APPCOMMAND_BROWSER_HOME`) - BrowserHome, - /// Refresh the current page or content. (`APPCOMMAND_BROWSER_REFRESH`) - BrowserRefresh, - /// Call up the user’s preferred search page. (`APPCOMMAND_BROWSER_SEARCH`) - BrowserSearch, - /// Stop loading the current page or content. (`APPCOMMAND_BROWSER_STOP`) - BrowserStop, - /// The Application switch key, which provides a list of recent apps to switch between. - /// (`KEYCODE_APP_SWITCH`) - AppSwitch, - /// The Call key. (`KEYCODE_CALL`) - Call, - /// The Camera key. (`KEYCODE_CAMERA`) - Camera, - /// The Camera focus key. (`KEYCODE_FOCUS`) - CameraFocus, - /// The End Call key. (`KEYCODE_ENDCALL`) - EndCall, - /// The Back key. (`KEYCODE_BACK`) - GoBack, - /// The Home key, which goes to the phone’s main screen. (`KEYCODE_HOME`) - GoHome, - /// The Headset Hook key. (`KEYCODE_HEADSETHOOK`) - HeadsetHook, - LastNumberRedial, - /// The Notification key. (`KEYCODE_NOTIFICATION`) - Notification, - /// Toggle between manner mode state: silent, vibrate, ring, ... (`KEYCODE_MANNER_MODE`) - MannerMode, - VoiceDial, - /// Switch to viewing TV. (`KEYCODE_TV`) - TV, - /// TV 3D Mode. (`KEYCODE_3D_MODE`) - TV3DMode, - /// Toggle between antenna and cable input. (`KEYCODE_TV_ANTENNA_CABLE`) - TVAntennaCable, - /// Audio description. (`KEYCODE_TV_AUDIO_DESCRIPTION`) - TVAudioDescription, - /// Audio description mixing volume down. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN`) - TVAudioDescriptionMixDown, - /// Audio description mixing volume up. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP`) - TVAudioDescriptionMixUp, - /// Contents menu. (`KEYCODE_TV_CONTENTS_MENU`) - TVContentsMenu, - /// Contents menu. (`KEYCODE_TV_DATA_SERVICE`) - TVDataService, - /// Switch the input mode on an external TV. (`KEYCODE_TV_INPUT`) - TVInput, - /// Switch to component input #1. (`KEYCODE_TV_INPUT_COMPONENT_1`) - TVInputComponent1, - /// Switch to component input #2. (`KEYCODE_TV_INPUT_COMPONENT_2`) - TVInputComponent2, - /// Switch to composite input #1. (`KEYCODE_TV_INPUT_COMPOSITE_1`) - TVInputComposite1, - /// Switch to composite input #2. (`KEYCODE_TV_INPUT_COMPOSITE_2`) - TVInputComposite2, - /// Switch to HDMI input #1. (`KEYCODE_TV_INPUT_HDMI_1`) - TVInputHDMI1, - /// Switch to HDMI input #2. (`KEYCODE_TV_INPUT_HDMI_2`) - TVInputHDMI2, - /// Switch to HDMI input #3. (`KEYCODE_TV_INPUT_HDMI_3`) - TVInputHDMI3, - /// Switch to HDMI input #4. (`KEYCODE_TV_INPUT_HDMI_4`) - TVInputHDMI4, - /// Switch to VGA input #1. (`KEYCODE_TV_INPUT_VGA_1`) - TVInputVGA1, - /// Media context menu. (`KEYCODE_TV_MEDIA_CONTEXT_MENU`) - TVMediaContext, - /// Toggle network. (`KEYCODE_TV_NETWORK`) - TVNetwork, - /// Number entry. (`KEYCODE_TV_NUMBER_ENTRY`) - TVNumberEntry, - /// Toggle the power on an external TV. (`KEYCODE_TV_POWER`) - TVPower, - /// Radio. (`KEYCODE_TV_RADIO_SERVICE`) - TVRadioService, - /// Satellite. (`KEYCODE_TV_SATELLITE`) - TVSatellite, - /// Broadcast Satellite. (`KEYCODE_TV_SATELLITE_BS`) - TVSatelliteBS, - /// Communication Satellite. (`KEYCODE_TV_SATELLITE_CS`) - TVSatelliteCS, - /// Toggle between available satellites. (`KEYCODE_TV_SATELLITE_SERVICE`) - TVSatelliteToggle, - /// Analog Terrestrial. (`KEYCODE_TV_TERRESTRIAL_ANALOG`) - TVTerrestrialAnalog, - /// Digital Terrestrial. (`KEYCODE_TV_TERRESTRIAL_DIGITAL`) - TVTerrestrialDigital, - /// Timer programming. (`KEYCODE_TV_TIMER_PROGRAMMING`) - TVTimer, - /// Switch the input mode on an external AVR (audio/video receiver). (`KEYCODE_AVR_INPUT`) - AVRInput, - /// Toggle the power on an external AVR (audio/video receiver). (`KEYCODE_AVR_POWER`) - AVRPower, - /// General purpose color-coded media function key, as index 0 (red). (`VK_COLORED_KEY_0`, - /// `KEYCODE_PROG_RED`) - ColorF0Red, - /// General purpose color-coded media function key, as index 1 (green). (`VK_COLORED_KEY_1`, - /// `KEYCODE_PROG_GREEN`) - ColorF1Green, - /// General purpose color-coded media function key, as index 2 (yellow). (`VK_COLORED_KEY_2`, - /// `KEYCODE_PROG_YELLOW`) - ColorF2Yellow, - /// General purpose color-coded media function key, as index 3 (blue). (`VK_COLORED_KEY_3`, - /// `KEYCODE_PROG_BLUE`) - ColorF3Blue, - /// General purpose color-coded media function key, as index 4 (grey). (`VK_COLORED_KEY_4`) - ColorF4Grey, - /// General purpose color-coded media function key, as index 5 (brown). (`VK_COLORED_KEY_5`) - ColorF5Brown, - /// Toggle the display of Closed Captions. (`VK_CC`, `KEYCODE_CAPTIONS`) - ClosedCaptionToggle, - /// Adjust brightness of device, by toggling between or cycling through states. (`VK_DIMMER`) - Dimmer, - /// Swap video sources. (`VK_DISPLAY_SWAP`) - DisplaySwap, - /// Select Digital Video Recorder. (`KEYCODE_DVR`) - DVR, - /// Exit the current application. (`VK_EXIT`) - Exit, - /// Clear program or content stored as favorite 0. (`VK_CLEAR_FAVORITE_0`) - FavoriteClear0, - /// Clear program or content stored as favorite 1. (`VK_CLEAR_FAVORITE_1`) - FavoriteClear1, - /// Clear program or content stored as favorite 2. (`VK_CLEAR_FAVORITE_2`) - FavoriteClear2, - /// Clear program or content stored as favorite 3. (`VK_CLEAR_FAVORITE_3`) - FavoriteClear3, - /// Select (recall) program or content stored as favorite 0. (`VK_RECALL_FAVORITE_0`) - FavoriteRecall0, - /// Select (recall) program or content stored as favorite 1. (`VK_RECALL_FAVORITE_1`) - FavoriteRecall1, - /// Select (recall) program or content stored as favorite 2. (`VK_RECALL_FAVORITE_2`) - FavoriteRecall2, - /// Select (recall) program or content stored as favorite 3. (`VK_RECALL_FAVORITE_3`) - FavoriteRecall3, - /// Store current program or content as favorite 0. (`VK_STORE_FAVORITE_0`) - FavoriteStore0, - /// Store current program or content as favorite 1. (`VK_STORE_FAVORITE_1`) - FavoriteStore1, - /// Store current program or content as favorite 2. (`VK_STORE_FAVORITE_2`) - FavoriteStore2, - /// Store current program or content as favorite 3. (`VK_STORE_FAVORITE_3`) - FavoriteStore3, - /// Toggle display of program or content guide. (`VK_GUIDE`, `KEYCODE_GUIDE`) - Guide, - /// If guide is active and displayed, then display next day’s content. (`VK_NEXT_DAY`) - GuideNextDay, - /// If guide is active and displayed, then display previous day’s content. (`VK_PREV_DAY`) - GuidePreviousDay, - /// Toggle display of information about currently selected context or media. (`VK_INFO`, - /// `KEYCODE_INFO`) - Info, - /// Toggle instant replay. (`VK_INSTANT_REPLAY`) - InstantReplay, - /// Launch linked content, if available and appropriate. (`VK_LINK`) - Link, - /// List the current program. (`VK_LIST`) - ListProgram, - /// Toggle display listing of currently available live content or programs. (`VK_LIVE`) - LiveContent, - /// Lock or unlock current content or program. (`VK_LOCK`) - Lock, - /// Show a list of media applications: audio/video players and image viewers. (`VK_APPS`) - /// - /// Note: Do not confuse this key value with the Windows' `VK_APPS` / `VK_CONTEXT_MENU` key, - /// which is encoded as `"ContextMenu"`. - MediaApps, - /// Audio track key. (`KEYCODE_MEDIA_AUDIO_TRACK`) - MediaAudioTrack, - /// Select previously selected channel or media. (`VK_LAST`, `KEYCODE_LAST_CHANNEL`) - MediaLast, - /// Skip backward to next content or program. (`KEYCODE_MEDIA_SKIP_BACKWARD`) - MediaSkipBackward, - /// Skip forward to next content or program. (`VK_SKIP`, `KEYCODE_MEDIA_SKIP_FORWARD`) - MediaSkipForward, - /// Step backward to next content or program. (`KEYCODE_MEDIA_STEP_BACKWARD`) - MediaStepBackward, - /// Step forward to next content or program. (`KEYCODE_MEDIA_STEP_FORWARD`) - MediaStepForward, - /// Media top menu. (`KEYCODE_MEDIA_TOP_MENU`) - MediaTopMenu, - /// Navigate in. (`KEYCODE_NAVIGATE_IN`) - NavigateIn, - /// Navigate to next key. (`KEYCODE_NAVIGATE_NEXT`) - NavigateNext, - /// Navigate out. (`KEYCODE_NAVIGATE_OUT`) - NavigateOut, - /// Navigate to previous key. (`KEYCODE_NAVIGATE_PREVIOUS`) - NavigatePrevious, - /// Cycle to next favorite channel (in favorites list). (`VK_NEXT_FAVORITE_CHANNEL`) - NextFavoriteChannel, - /// Cycle to next user profile (if there are multiple user profiles). (`VK_USER`) - NextUserProfile, - /// Access on-demand content or programs. (`VK_ON_DEMAND`) - OnDemand, - /// Pairing key to pair devices. (`KEYCODE_PAIRING`) - Pairing, - /// Move picture-in-picture window down. (`VK_PINP_DOWN`) - PinPDown, - /// Move picture-in-picture window. (`VK_PINP_MOVE`) - PinPMove, - /// Toggle display of picture-in-picture window. (`VK_PINP_TOGGLE`) - PinPToggle, - /// Move picture-in-picture window up. (`VK_PINP_UP`) - PinPUp, - /// Decrease media playback speed. (`VK_PLAY_SPEED_DOWN`) - PlaySpeedDown, - /// Reset playback to normal speed. (`VK_PLAY_SPEED_RESET`) - PlaySpeedReset, - /// Increase media playback speed. (`VK_PLAY_SPEED_UP`) - PlaySpeedUp, - /// Toggle random media or content shuffle mode. (`VK_RANDOM_TOGGLE`) - RandomToggle, - /// Not a physical key, but this key code is sent when the remote control battery is low. - /// (`VK_RC_LOW_BATTERY`) - RcLowBattery, - /// Toggle or cycle between media recording speeds. (`VK_RECORD_SPEED_NEXT`) - RecordSpeedNext, - /// Toggle RF (radio frequency) input bypass mode (pass RF input directly to the RF output). - /// (`VK_RF_BYPASS`) - RfBypass, - /// Toggle scan channels mode. (`VK_SCAN_CHANNELS_TOGGLE`) - ScanChannelsToggle, - /// Advance display screen mode to next available mode. (`VK_SCREEN_MODE_NEXT`) - ScreenModeNext, - /// Toggle display of device settings screen. (`VK_SETTINGS`, `KEYCODE_SETTINGS`) - Settings, - /// Toggle split screen mode. (`VK_SPLIT_SCREEN_TOGGLE`) - SplitScreenToggle, - /// Switch the input mode on an external STB (set top box). (`KEYCODE_STB_INPUT`) - STBInput, - /// Toggle the power on an external STB (set top box). (`KEYCODE_STB_POWER`) - STBPower, - /// Toggle display of subtitles, if available. (`VK_SUBTITLE`) - Subtitle, - /// Toggle display of teletext, if available (`VK_TELETEXT`, `KEYCODE_TV_TELETEXT`). - Teletext, - /// Advance video mode to next available mode. (`VK_VIDEO_MODE_NEXT`) - VideoModeNext, - /// Cause device to identify itself in some manner, e.g., audibly or visibly. (`VK_WINK`) - Wink, - /// Toggle between full-screen and scaled content, or alter magnification level. (`VK_ZOOM`, - /// `KEYCODE_TV_ZOOM_MODE`) - ZoomToggle, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F1, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F2, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F3, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F4, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F5, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F6, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F7, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F8, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F9, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F10, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F11, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F12, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F13, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F14, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F15, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F16, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F17, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F18, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F19, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F20, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F21, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F22, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F23, - /// General-purpose function key. - /// Usually found at the top of the keyboard. - F24, - /// General-purpose function key. - F25, - /// General-purpose function key. - F26, - /// General-purpose function key. - F27, - /// General-purpose function key. - F28, - /// General-purpose function key. - F29, - /// General-purpose function key. - F30, - /// General-purpose function key. - F31, - /// General-purpose function key. - F32, - /// General-purpose function key. - F33, - /// General-purpose function key. - F34, - /// General-purpose function key. - F35, -} - /// Key represents the meaning of a keypress. /// /// This is a superset of the UI Events Specification's [`KeyboardEvent.key`] with @@ -1554,33 +328,6 @@ impl Key { } } -impl NamedKey { - /// Convert an action to its approximate textual equivalent. - /// - /// # Examples - /// - /// ``` - /// # #[cfg(target_family = "wasm")] - /// # wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); - /// # #[cfg_attr(target_family = "wasm", wasm_bindgen_test::wasm_bindgen_test)] - /// # fn main() { - /// use winit_core::keyboard::NamedKey; - /// - /// assert_eq!(NamedKey::Enter.to_text(), Some("\r")); - /// assert_eq!(NamedKey::F20.to_text(), None); - /// # } - /// ``` - pub fn to_text(&self) -> Option<&str> { - match self { - NamedKey::Enter => Some("\r"), - NamedKey::Backspace => Some("\x08"), - NamedKey::Tab => Some("\t"), - NamedKey::Escape => Some("\x1b"), - _ => None, - } - } -} - impl Key { /// Convert a key to its approximate textual equivalent. /// @@ -1600,92 +347,19 @@ impl Key { /// ``` pub fn to_text(&self) -> Option<&str> { match self { - Key::Named(action) => action.to_text(), + Key::Named(action) => match action { + NamedKey::Enter => Some("\r"), + NamedKey::Backspace => Some("\x08"), + NamedKey::Tab => Some("\t"), + NamedKey::Escape => Some("\x1b"), + _ => None, + }, Key::Character(ch) => Some(ch.as_str()), _ => None, } } } -/// The location of the key on the keyboard. -/// -/// Certain physical keys on the keyboard can have the same value, but are in different locations. -/// For instance, the Shift key can be on the left or right side of the keyboard, or the number -/// keys can be above the letters or on the numpad. This enum allows the user to differentiate -/// them. -/// -/// See the documentation for the [`location`] field on the [`KeyEvent`] struct for more -/// information. -/// -/// [`location`]: ../event/struct.KeyEvent.html#structfield.location -/// [`KeyEvent`]: crate::event::KeyEvent -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum KeyLocation { - /// The key is in its "normal" location on the keyboard. - /// - /// For instance, the "1" key above the "Q" key on a QWERTY keyboard will use this location. - /// This invariant is also returned when the location of the key cannot be identified. - /// - /// ![Standard 1 key](https://raw.githubusercontent.com/rust-windowing/winit/master/docs/res/keyboard_standard_1_key.svg) - /// - /// - /// For image attribution, see the - /// - /// ATTRIBUTION.md - /// - /// file. - /// - Standard, - - /// The key is on the left side of the keyboard. - /// - /// For instance, the left Shift key below the Caps Lock key on a QWERTY keyboard will use this - /// location. - /// - /// ![Left Shift key](https://raw.githubusercontent.com/rust-windowing/winit/master/docs/res/keyboard_left_shift_key.svg) - /// - /// - /// For image attribution, see the - /// - /// ATTRIBUTION.md - /// - /// file. - /// - Left, - - /// The key is on the right side of the keyboard. - /// - /// For instance, the right Shift key below the Enter key on a QWERTY keyboard will use this - /// location. - /// - /// ![Right Shift key](https://raw.githubusercontent.com/rust-windowing/winit/master/docs/res/keyboard_right_shift_key.svg) - /// - /// - /// For image attribution, see the - /// - /// ATTRIBUTION.md - /// - /// file. - /// - Right, - - /// The key is on the numpad. - /// - /// For instance, the "1" key on the numpad will use this location. - /// - /// ![Numpad 1 key](https://raw.githubusercontent.com/rust-windowing/winit/master/docs/res/keyboard_numpad_1_key.svg) - /// - /// - /// For image attribution, see the - /// - /// ATTRIBUTION.md - /// - /// file. - /// - Numpad, -} - bitflags! { /// Represents the current logical state of the keyboard modifiers /// diff --git a/winit-web/src/keyboard.rs b/winit-web/src/keyboard.rs deleted file mode 100644 index dae75db3..00000000 --- a/winit-web/src/keyboard.rs +++ /dev/null @@ -1,530 +0,0 @@ -use smol_str::SmolStr; -use winit_core::keyboard::{Key, KeyCode, NamedKey, NativeKey, NativeKeyCode, PhysicalKey}; - -pub trait FromAttributeValue { - fn from_attribute_value(kav: &str) -> Self - where - Self: Sized; -} - -impl FromAttributeValue for Key { - fn from_attribute_value(kav: &str) -> Self { - Key::Named(match kav { - "Unidentified" => return Key::Unidentified(NativeKey::Web(SmolStr::new(kav))), - "Dead" => return Key::Dead(None), - "Alt" => NamedKey::Alt, - "AltGraph" => NamedKey::AltGraph, - "CapsLock" => NamedKey::CapsLock, - "Control" => NamedKey::Control, - "Fn" => NamedKey::Fn, - "FnLock" => NamedKey::FnLock, - "NumLock" => NamedKey::NumLock, - "ScrollLock" => NamedKey::ScrollLock, - "Shift" => NamedKey::Shift, - "Symbol" => NamedKey::Symbol, - "SymbolLock" => NamedKey::SymbolLock, - #[allow(deprecated)] - "Super" => NamedKey::Super, - #[allow(deprecated)] - "Hyper" => NamedKey::Hyper, - "Meta" => NamedKey::Meta, - "Enter" => NamedKey::Enter, - "Tab" => NamedKey::Tab, - "ArrowDown" => NamedKey::ArrowDown, - "ArrowLeft" => NamedKey::ArrowLeft, - "ArrowRight" => NamedKey::ArrowRight, - "ArrowUp" => NamedKey::ArrowUp, - "End" => NamedKey::End, - "Home" => NamedKey::Home, - "PageDown" => NamedKey::PageDown, - "PageUp" => NamedKey::PageUp, - "Backspace" => NamedKey::Backspace, - "Clear" => NamedKey::Clear, - "Copy" => NamedKey::Copy, - "CrSel" => NamedKey::CrSel, - "Cut" => NamedKey::Cut, - "Delete" => NamedKey::Delete, - "EraseEof" => NamedKey::EraseEof, - "ExSel" => NamedKey::ExSel, - "Insert" => NamedKey::Insert, - "Paste" => NamedKey::Paste, - "Redo" => NamedKey::Redo, - "Undo" => NamedKey::Undo, - "Accept" => NamedKey::Accept, - "Again" => NamedKey::Again, - "Attn" => NamedKey::Attn, - "Cancel" => NamedKey::Cancel, - "ContextMenu" => NamedKey::ContextMenu, - "Escape" => NamedKey::Escape, - "Execute" => NamedKey::Execute, - "Find" => NamedKey::Find, - "Help" => NamedKey::Help, - "Pause" => NamedKey::Pause, - "Play" => NamedKey::Play, - "Props" => NamedKey::Props, - "Select" => NamedKey::Select, - "ZoomIn" => NamedKey::ZoomIn, - "ZoomOut" => NamedKey::ZoomOut, - "BrightnessDown" => NamedKey::BrightnessDown, - "BrightnessUp" => NamedKey::BrightnessUp, - "Eject" => NamedKey::Eject, - "LogOff" => NamedKey::LogOff, - "Power" => NamedKey::Power, - "PowerOff" => NamedKey::PowerOff, - "PrintScreen" => NamedKey::PrintScreen, - "Hibernate" => NamedKey::Hibernate, - "Standby" => NamedKey::Standby, - "WakeUp" => NamedKey::WakeUp, - "AllCandidates" => NamedKey::AllCandidates, - "Alphanumeric" => NamedKey::Alphanumeric, - "CodeInput" => NamedKey::CodeInput, - "Compose" => NamedKey::Compose, - "Convert" => NamedKey::Convert, - "FinalMode" => NamedKey::FinalMode, - "GroupFirst" => NamedKey::GroupFirst, - "GroupLast" => NamedKey::GroupLast, - "GroupNext" => NamedKey::GroupNext, - "GroupPrevious" => NamedKey::GroupPrevious, - "ModeChange" => NamedKey::ModeChange, - "NextCandidate" => NamedKey::NextCandidate, - "NonConvert" => NamedKey::NonConvert, - "PreviousCandidate" => NamedKey::PreviousCandidate, - "Process" => NamedKey::Process, - "SingleCandidate" => NamedKey::SingleCandidate, - "HangulMode" => NamedKey::HangulMode, - "HanjaMode" => NamedKey::HanjaMode, - "JunjaMode" => NamedKey::JunjaMode, - "Eisu" => NamedKey::Eisu, - "Hankaku" => NamedKey::Hankaku, - "Hiragana" => NamedKey::Hiragana, - "HiraganaKatakana" => NamedKey::HiraganaKatakana, - "KanaMode" => NamedKey::KanaMode, - "KanjiMode" => NamedKey::KanjiMode, - "Katakana" => NamedKey::Katakana, - "Romaji" => NamedKey::Romaji, - "Zenkaku" => NamedKey::Zenkaku, - "ZenkakuHankaku" => NamedKey::ZenkakuHankaku, - "Soft1" => NamedKey::Soft1, - "Soft2" => NamedKey::Soft2, - "Soft3" => NamedKey::Soft3, - "Soft4" => NamedKey::Soft4, - "ChannelDown" => NamedKey::ChannelDown, - "ChannelUp" => NamedKey::ChannelUp, - "Close" => NamedKey::Close, - "MailForward" => NamedKey::MailForward, - "MailReply" => NamedKey::MailReply, - "MailSend" => NamedKey::MailSend, - "MediaClose" => NamedKey::MediaClose, - "MediaFastForward" => NamedKey::MediaFastForward, - "MediaPause" => NamedKey::MediaPause, - "MediaPlay" => NamedKey::MediaPlay, - "MediaPlayPause" => NamedKey::MediaPlayPause, - "MediaRecord" => NamedKey::MediaRecord, - "MediaRewind" => NamedKey::MediaRewind, - "MediaStop" => NamedKey::MediaStop, - "MediaTrackNext" => NamedKey::MediaTrackNext, - "MediaTrackPrevious" => NamedKey::MediaTrackPrevious, - "New" => NamedKey::New, - "Open" => NamedKey::Open, - "Print" => NamedKey::Print, - "Save" => NamedKey::Save, - "SpellCheck" => NamedKey::SpellCheck, - "Key11" => NamedKey::Key11, - "Key12" => NamedKey::Key12, - "AudioBalanceLeft" => NamedKey::AudioBalanceLeft, - "AudioBalanceRight" => NamedKey::AudioBalanceRight, - "AudioBassBoostDown" => NamedKey::AudioBassBoostDown, - "AudioBassBoostToggle" => NamedKey::AudioBassBoostToggle, - "AudioBassBoostUp" => NamedKey::AudioBassBoostUp, - "AudioFaderFront" => NamedKey::AudioFaderFront, - "AudioFaderRear" => NamedKey::AudioFaderRear, - "AudioSurroundModeNext" => NamedKey::AudioSurroundModeNext, - "AudioTrebleDown" => NamedKey::AudioTrebleDown, - "AudioTrebleUp" => NamedKey::AudioTrebleUp, - "AudioVolumeDown" => NamedKey::AudioVolumeDown, - "AudioVolumeUp" => NamedKey::AudioVolumeUp, - "AudioVolumeMute" => NamedKey::AudioVolumeMute, - "MicrophoneToggle" => NamedKey::MicrophoneToggle, - "MicrophoneVolumeDown" => NamedKey::MicrophoneVolumeDown, - "MicrophoneVolumeUp" => NamedKey::MicrophoneVolumeUp, - "MicrophoneVolumeMute" => NamedKey::MicrophoneVolumeMute, - "SpeechCorrectionList" => NamedKey::SpeechCorrectionList, - "SpeechInputToggle" => NamedKey::SpeechInputToggle, - "LaunchApplication1" => NamedKey::LaunchApplication1, - "LaunchApplication2" => NamedKey::LaunchApplication2, - "LaunchCalendar" => NamedKey::LaunchCalendar, - "LaunchContacts" => NamedKey::LaunchContacts, - "LaunchMail" => NamedKey::LaunchMail, - "LaunchMediaPlayer" => NamedKey::LaunchMediaPlayer, - "LaunchMusicPlayer" => NamedKey::LaunchMusicPlayer, - "LaunchPhone" => NamedKey::LaunchPhone, - "LaunchScreenSaver" => NamedKey::LaunchScreenSaver, - "LaunchSpreadsheet" => NamedKey::LaunchSpreadsheet, - "LaunchWebBrowser" => NamedKey::LaunchWebBrowser, - "LaunchWebCam" => NamedKey::LaunchWebCam, - "LaunchWordProcessor" => NamedKey::LaunchWordProcessor, - "BrowserBack" => NamedKey::BrowserBack, - "BrowserFavorites" => NamedKey::BrowserFavorites, - "BrowserForward" => NamedKey::BrowserForward, - "BrowserHome" => NamedKey::BrowserHome, - "BrowserRefresh" => NamedKey::BrowserRefresh, - "BrowserSearch" => NamedKey::BrowserSearch, - "BrowserStop" => NamedKey::BrowserStop, - "AppSwitch" => NamedKey::AppSwitch, - "Call" => NamedKey::Call, - "Camera" => NamedKey::Camera, - "CameraFocus" => NamedKey::CameraFocus, - "EndCall" => NamedKey::EndCall, - "GoBack" => NamedKey::GoBack, - "GoHome" => NamedKey::GoHome, - "HeadsetHook" => NamedKey::HeadsetHook, - "LastNumberRedial" => NamedKey::LastNumberRedial, - "Notification" => NamedKey::Notification, - "MannerMode" => NamedKey::MannerMode, - "VoiceDial" => NamedKey::VoiceDial, - "TV" => NamedKey::TV, - "TV3DMode" => NamedKey::TV3DMode, - "TVAntennaCable" => NamedKey::TVAntennaCable, - "TVAudioDescription" => NamedKey::TVAudioDescription, - "TVAudioDescriptionMixDown" => NamedKey::TVAudioDescriptionMixDown, - "TVAudioDescriptionMixUp" => NamedKey::TVAudioDescriptionMixUp, - "TVContentsMenu" => NamedKey::TVContentsMenu, - "TVDataService" => NamedKey::TVDataService, - "TVInput" => NamedKey::TVInput, - "TVInputComponent1" => NamedKey::TVInputComponent1, - "TVInputComponent2" => NamedKey::TVInputComponent2, - "TVInputComposite1" => NamedKey::TVInputComposite1, - "TVInputComposite2" => NamedKey::TVInputComposite2, - "TVInputHDMI1" => NamedKey::TVInputHDMI1, - "TVInputHDMI2" => NamedKey::TVInputHDMI2, - "TVInputHDMI3" => NamedKey::TVInputHDMI3, - "TVInputHDMI4" => NamedKey::TVInputHDMI4, - "TVInputVGA1" => NamedKey::TVInputVGA1, - "TVMediaContext" => NamedKey::TVMediaContext, - "TVNetwork" => NamedKey::TVNetwork, - "TVNumberEntry" => NamedKey::TVNumberEntry, - "TVPower" => NamedKey::TVPower, - "TVRadioService" => NamedKey::TVRadioService, - "TVSatellite" => NamedKey::TVSatellite, - "TVSatelliteBS" => NamedKey::TVSatelliteBS, - "TVSatelliteCS" => NamedKey::TVSatelliteCS, - "TVSatelliteToggle" => NamedKey::TVSatelliteToggle, - "TVTerrestrialAnalog" => NamedKey::TVTerrestrialAnalog, - "TVTerrestrialDigital" => NamedKey::TVTerrestrialDigital, - "TVTimer" => NamedKey::TVTimer, - "AVRInput" => NamedKey::AVRInput, - "AVRPower" => NamedKey::AVRPower, - "ColorF0Red" => NamedKey::ColorF0Red, - "ColorF1Green" => NamedKey::ColorF1Green, - "ColorF2Yellow" => NamedKey::ColorF2Yellow, - "ColorF3Blue" => NamedKey::ColorF3Blue, - "ColorF4Grey" => NamedKey::ColorF4Grey, - "ColorF5Brown" => NamedKey::ColorF5Brown, - "ClosedCaptionToggle" => NamedKey::ClosedCaptionToggle, - "Dimmer" => NamedKey::Dimmer, - "DisplaySwap" => NamedKey::DisplaySwap, - "DVR" => NamedKey::DVR, - "Exit" => NamedKey::Exit, - "FavoriteClear0" => NamedKey::FavoriteClear0, - "FavoriteClear1" => NamedKey::FavoriteClear1, - "FavoriteClear2" => NamedKey::FavoriteClear2, - "FavoriteClear3" => NamedKey::FavoriteClear3, - "FavoriteRecall0" => NamedKey::FavoriteRecall0, - "FavoriteRecall1" => NamedKey::FavoriteRecall1, - "FavoriteRecall2" => NamedKey::FavoriteRecall2, - "FavoriteRecall3" => NamedKey::FavoriteRecall3, - "FavoriteStore0" => NamedKey::FavoriteStore0, - "FavoriteStore1" => NamedKey::FavoriteStore1, - "FavoriteStore2" => NamedKey::FavoriteStore2, - "FavoriteStore3" => NamedKey::FavoriteStore3, - "Guide" => NamedKey::Guide, - "GuideNextDay" => NamedKey::GuideNextDay, - "GuidePreviousDay" => NamedKey::GuidePreviousDay, - "Info" => NamedKey::Info, - "InstantReplay" => NamedKey::InstantReplay, - "Link" => NamedKey::Link, - "ListProgram" => NamedKey::ListProgram, - "LiveContent" => NamedKey::LiveContent, - "Lock" => NamedKey::Lock, - "MediaApps" => NamedKey::MediaApps, - "MediaAudioTrack" => NamedKey::MediaAudioTrack, - "MediaLast" => NamedKey::MediaLast, - "MediaSkipBackward" => NamedKey::MediaSkipBackward, - "MediaSkipForward" => NamedKey::MediaSkipForward, - "MediaStepBackward" => NamedKey::MediaStepBackward, - "MediaStepForward" => NamedKey::MediaStepForward, - "MediaTopMenu" => NamedKey::MediaTopMenu, - "NavigateIn" => NamedKey::NavigateIn, - "NavigateNext" => NamedKey::NavigateNext, - "NavigateOut" => NamedKey::NavigateOut, - "NavigatePrevious" => NamedKey::NavigatePrevious, - "NextFavoriteChannel" => NamedKey::NextFavoriteChannel, - "NextUserProfile" => NamedKey::NextUserProfile, - "OnDemand" => NamedKey::OnDemand, - "Pairing" => NamedKey::Pairing, - "PinPDown" => NamedKey::PinPDown, - "PinPMove" => NamedKey::PinPMove, - "PinPToggle" => NamedKey::PinPToggle, - "PinPUp" => NamedKey::PinPUp, - "PlaySpeedDown" => NamedKey::PlaySpeedDown, - "PlaySpeedReset" => NamedKey::PlaySpeedReset, - "PlaySpeedUp" => NamedKey::PlaySpeedUp, - "RandomToggle" => NamedKey::RandomToggle, - "RcLowBattery" => NamedKey::RcLowBattery, - "RecordSpeedNext" => NamedKey::RecordSpeedNext, - "RfBypass" => NamedKey::RfBypass, - "ScanChannelsToggle" => NamedKey::ScanChannelsToggle, - "ScreenModeNext" => NamedKey::ScreenModeNext, - "Settings" => NamedKey::Settings, - "SplitScreenToggle" => NamedKey::SplitScreenToggle, - "STBInput" => NamedKey::STBInput, - "STBPower" => NamedKey::STBPower, - "Subtitle" => NamedKey::Subtitle, - "Teletext" => NamedKey::Teletext, - "VideoModeNext" => NamedKey::VideoModeNext, - "Wink" => NamedKey::Wink, - "ZoomToggle" => NamedKey::ZoomToggle, - "F1" => NamedKey::F1, - "F2" => NamedKey::F2, - "F3" => NamedKey::F3, - "F4" => NamedKey::F4, - "F5" => NamedKey::F5, - "F6" => NamedKey::F6, - "F7" => NamedKey::F7, - "F8" => NamedKey::F8, - "F9" => NamedKey::F9, - "F10" => NamedKey::F10, - "F11" => NamedKey::F11, - "F12" => NamedKey::F12, - "F13" => NamedKey::F13, - "F14" => NamedKey::F14, - "F15" => NamedKey::F15, - "F16" => NamedKey::F16, - "F17" => NamedKey::F17, - "F18" => NamedKey::F18, - "F19" => NamedKey::F19, - "F20" => NamedKey::F20, - "F21" => NamedKey::F21, - "F22" => NamedKey::F22, - "F23" => NamedKey::F23, - "F24" => NamedKey::F24, - "F25" => NamedKey::F25, - "F26" => NamedKey::F26, - "F27" => NamedKey::F27, - "F28" => NamedKey::F28, - "F29" => NamedKey::F29, - "F30" => NamedKey::F30, - "F31" => NamedKey::F31, - "F32" => NamedKey::F32, - "F33" => NamedKey::F33, - "F34" => NamedKey::F34, - "F35" => NamedKey::F35, - string => return Key::Character(SmolStr::new(string)), - }) - } -} - -impl FromAttributeValue for PhysicalKey { - fn from_attribute_value(kcav: &str) -> Self { - PhysicalKey::Code(match kcav { - "Backquote" => KeyCode::Backquote, - "Backslash" => KeyCode::Backslash, - "BracketLeft" => KeyCode::BracketLeft, - "BracketRight" => KeyCode::BracketRight, - "Comma" => KeyCode::Comma, - "Digit0" => KeyCode::Digit0, - "Digit1" => KeyCode::Digit1, - "Digit2" => KeyCode::Digit2, - "Digit3" => KeyCode::Digit3, - "Digit4" => KeyCode::Digit4, - "Digit5" => KeyCode::Digit5, - "Digit6" => KeyCode::Digit6, - "Digit7" => KeyCode::Digit7, - "Digit8" => KeyCode::Digit8, - "Digit9" => KeyCode::Digit9, - "Equal" => KeyCode::Equal, - "IntlBackslash" => KeyCode::IntlBackslash, - "IntlRo" => KeyCode::IntlRo, - "IntlYen" => KeyCode::IntlYen, - "KeyA" => KeyCode::KeyA, - "KeyB" => KeyCode::KeyB, - "KeyC" => KeyCode::KeyC, - "KeyD" => KeyCode::KeyD, - "KeyE" => KeyCode::KeyE, - "KeyF" => KeyCode::KeyF, - "KeyG" => KeyCode::KeyG, - "KeyH" => KeyCode::KeyH, - "KeyI" => KeyCode::KeyI, - "KeyJ" => KeyCode::KeyJ, - "KeyK" => KeyCode::KeyK, - "KeyL" => KeyCode::KeyL, - "KeyM" => KeyCode::KeyM, - "KeyN" => KeyCode::KeyN, - "KeyO" => KeyCode::KeyO, - "KeyP" => KeyCode::KeyP, - "KeyQ" => KeyCode::KeyQ, - "KeyR" => KeyCode::KeyR, - "KeyS" => KeyCode::KeyS, - "KeyT" => KeyCode::KeyT, - "KeyU" => KeyCode::KeyU, - "KeyV" => KeyCode::KeyV, - "KeyW" => KeyCode::KeyW, - "KeyX" => KeyCode::KeyX, - "KeyY" => KeyCode::KeyY, - "KeyZ" => KeyCode::KeyZ, - "Minus" => KeyCode::Minus, - "Period" => KeyCode::Period, - "Quote" => KeyCode::Quote, - "Semicolon" => KeyCode::Semicolon, - "Slash" => KeyCode::Slash, - "AltLeft" => KeyCode::AltLeft, - "AltRight" => KeyCode::AltRight, - "Backspace" => KeyCode::Backspace, - "CapsLock" => KeyCode::CapsLock, - "ContextMenu" => KeyCode::ContextMenu, - "ControlLeft" => KeyCode::ControlLeft, - "ControlRight" => KeyCode::ControlRight, - "Enter" => KeyCode::Enter, - "MetaLeft" => KeyCode::MetaLeft, - "MetaRight" => KeyCode::MetaRight, - "ShiftLeft" => KeyCode::ShiftLeft, - "ShiftRight" => KeyCode::ShiftRight, - "Space" => KeyCode::Space, - "Tab" => KeyCode::Tab, - "Convert" => KeyCode::Convert, - "KanaMode" => KeyCode::KanaMode, - "Lang1" => KeyCode::Lang1, - "Lang2" => KeyCode::Lang2, - "Lang3" => KeyCode::Lang3, - "Lang4" => KeyCode::Lang4, - "Lang5" => KeyCode::Lang5, - "NonConvert" => KeyCode::NonConvert, - "Delete" => KeyCode::Delete, - "End" => KeyCode::End, - "Help" => KeyCode::Help, - "Home" => KeyCode::Home, - "Insert" => KeyCode::Insert, - "PageDown" => KeyCode::PageDown, - "PageUp" => KeyCode::PageUp, - "ArrowDown" => KeyCode::ArrowDown, - "ArrowLeft" => KeyCode::ArrowLeft, - "ArrowRight" => KeyCode::ArrowRight, - "ArrowUp" => KeyCode::ArrowUp, - "NumLock" => KeyCode::NumLock, - "Numpad0" => KeyCode::Numpad0, - "Numpad1" => KeyCode::Numpad1, - "Numpad2" => KeyCode::Numpad2, - "Numpad3" => KeyCode::Numpad3, - "Numpad4" => KeyCode::Numpad4, - "Numpad5" => KeyCode::Numpad5, - "Numpad6" => KeyCode::Numpad6, - "Numpad7" => KeyCode::Numpad7, - "Numpad8" => KeyCode::Numpad8, - "Numpad9" => KeyCode::Numpad9, - "NumpadAdd" => KeyCode::NumpadAdd, - "NumpadBackspace" => KeyCode::NumpadBackspace, - "NumpadClear" => KeyCode::NumpadClear, - "NumpadClearEntry" => KeyCode::NumpadClearEntry, - "NumpadComma" => KeyCode::NumpadComma, - "NumpadDecimal" => KeyCode::NumpadDecimal, - "NumpadDivide" => KeyCode::NumpadDivide, - "NumpadEnter" => KeyCode::NumpadEnter, - "NumpadEqual" => KeyCode::NumpadEqual, - "NumpadHash" => KeyCode::NumpadHash, - "NumpadMemoryAdd" => KeyCode::NumpadMemoryAdd, - "NumpadMemoryClear" => KeyCode::NumpadMemoryClear, - "NumpadMemoryRecall" => KeyCode::NumpadMemoryRecall, - "NumpadMemoryStore" => KeyCode::NumpadMemoryStore, - "NumpadMemorySubtract" => KeyCode::NumpadMemorySubtract, - "NumpadMultiply" => KeyCode::NumpadMultiply, - "NumpadParenLeft" => KeyCode::NumpadParenLeft, - "NumpadParenRight" => KeyCode::NumpadParenRight, - "NumpadStar" => KeyCode::NumpadStar, - "NumpadSubtract" => KeyCode::NumpadSubtract, - "Escape" => KeyCode::Escape, - "Fn" => KeyCode::Fn, - "FnLock" => KeyCode::FnLock, - "PrintScreen" => KeyCode::PrintScreen, - "ScrollLock" => KeyCode::ScrollLock, - "Pause" => KeyCode::Pause, - "BrowserBack" => KeyCode::BrowserBack, - "BrowserFavorites" => KeyCode::BrowserFavorites, - "BrowserForward" => KeyCode::BrowserForward, - "BrowserHome" => KeyCode::BrowserHome, - "BrowserRefresh" => KeyCode::BrowserRefresh, - "BrowserSearch" => KeyCode::BrowserSearch, - "BrowserStop" => KeyCode::BrowserStop, - "Eject" => KeyCode::Eject, - "LaunchApp1" => KeyCode::LaunchApp1, - "LaunchApp2" => KeyCode::LaunchApp2, - "LaunchMail" => KeyCode::LaunchMail, - "MediaPlayPause" => KeyCode::MediaPlayPause, - "MediaSelect" => KeyCode::MediaSelect, - "MediaStop" => KeyCode::MediaStop, - "MediaTrackNext" => KeyCode::MediaTrackNext, - "MediaTrackPrevious" => KeyCode::MediaTrackPrevious, - "Power" => KeyCode::Power, - "Sleep" => KeyCode::Sleep, - "AudioVolumeDown" => KeyCode::AudioVolumeDown, - "AudioVolumeMute" => KeyCode::AudioVolumeMute, - "AudioVolumeUp" => KeyCode::AudioVolumeUp, - "WakeUp" => KeyCode::WakeUp, - #[allow(deprecated)] - "Super" => KeyCode::Super, - #[allow(deprecated)] - "Hyper" => KeyCode::Hyper, - #[allow(deprecated)] - "Turbo" => KeyCode::Turbo, - "Abort" => KeyCode::Abort, - "Resume" => KeyCode::Resume, - "Suspend" => KeyCode::Suspend, - "Again" => KeyCode::Again, - "Copy" => KeyCode::Copy, - "Cut" => KeyCode::Cut, - "Find" => KeyCode::Find, - "Open" => KeyCode::Open, - "Paste" => KeyCode::Paste, - "Props" => KeyCode::Props, - "Select" => KeyCode::Select, - "Undo" => KeyCode::Undo, - "Hiragana" => KeyCode::Hiragana, - "Katakana" => KeyCode::Katakana, - "F1" => KeyCode::F1, - "F2" => KeyCode::F2, - "F3" => KeyCode::F3, - "F4" => KeyCode::F4, - "F5" => KeyCode::F5, - "F6" => KeyCode::F6, - "F7" => KeyCode::F7, - "F8" => KeyCode::F8, - "F9" => KeyCode::F9, - "F10" => KeyCode::F10, - "F11" => KeyCode::F11, - "F12" => KeyCode::F12, - "F13" => KeyCode::F13, - "F14" => KeyCode::F14, - "F15" => KeyCode::F15, - "F16" => KeyCode::F16, - "F17" => KeyCode::F17, - "F18" => KeyCode::F18, - "F19" => KeyCode::F19, - "F20" => KeyCode::F20, - "F21" => KeyCode::F21, - "F22" => KeyCode::F22, - "F23" => KeyCode::F23, - "F24" => KeyCode::F24, - "F25" => KeyCode::F25, - "F26" => KeyCode::F26, - "F27" => KeyCode::F27, - "F28" => KeyCode::F28, - "F29" => KeyCode::F29, - "F30" => KeyCode::F30, - "F31" => KeyCode::F31, - "F32" => KeyCode::F32, - "F33" => KeyCode::F33, - "F34" => KeyCode::F34, - "F35" => KeyCode::F35, - _ => return PhysicalKey::Unidentified(NativeKeyCode::Unidentified), - }) - } -} diff --git a/winit-web/src/lib.rs b/winit-web/src/lib.rs index 946e47d4..3ea383c7 100644 --- a/winit-web/src/lib.rs +++ b/winit-web/src/lib.rs @@ -70,7 +70,6 @@ mod r#async; mod cursor; mod event; pub(crate) mod event_loop; -mod keyboard; mod lock; pub(crate) mod main_thread; mod monitor; diff --git a/winit-web/src/web_sys/event.rs b/winit-web/src/web_sys/event.rs index 849dff92..69a1635a 100644 --- a/winit-web/src/web_sys/event.rs +++ b/winit-web/src/web_sys/event.rs @@ -6,10 +6,11 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsCast, JsValue}; use web_sys::{KeyboardEvent, MouseEvent, Navigator, PointerEvent, WheelEvent}; use winit_core::event::{FingerId, MouseButton, MouseScrollDelta, PointerKind}; -use winit_core::keyboard::{Key, KeyLocation, ModifiersState, NamedKey, PhysicalKey}; +use winit_core::keyboard::{ + Key, KeyCode, KeyLocation, ModifiersState, NamedKey, NativeKey, NativeKeyCode, PhysicalKey, +}; use super::Engine; -use crate::keyboard::FromAttributeValue; bitflags::bitflags! { // https://www.w3.org/TR/pointerevents3/#the-buttons-property @@ -168,17 +169,32 @@ pub fn pointer_type(event: &PointerEvent, pointer_id: i32) -> PointerKind { } pub fn key_code(event: &KeyboardEvent) -> PhysicalKey { - let code = event.code(); - PhysicalKey::from_attribute_value(&code) + // Use keyboard-types' parsing (it is based on the W3C standard). + match event.code().parse() { + Ok(KeyCode::Unidentified) => PhysicalKey::Unidentified(NativeKeyCode::Unidentified), + Ok(code) => PhysicalKey::Code(code), + Err(err) => { + tracing::warn!("unknown keyboard input: {err}"); + PhysicalKey::Unidentified(NativeKeyCode::Unidentified) + }, + } } pub fn key(event: &KeyboardEvent) -> Key { - Key::from_attribute_value(&event.key()) + let key = event.key(); + // Use keyboard-types' parsing (it is based on the W3C standard). + match key.parse() { + Ok(NamedKey::Unidentified) => { + Key::Unidentified(NativeKey::Web(SmolStr::new("Unidentified"))) + }, + Ok(NamedKey::Dead) => Key::Dead(None), + Ok(named) => Key::Named(named), + Err(_) => Key::Character(SmolStr::new(key)), + } } pub fn key_text(event: &KeyboardEvent) -> Option { - let key = event.key(); - let key = Key::from_attribute_value(&key); + let key = key(event); match &key { Key::Character(text) => Some(text.clone()), Key::Named(NamedKey::Tab) => Some(SmolStr::new("\t")), diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index 741f92ef..d382032a 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -201,6 +201,7 @@ changelog entry. - Move `IconExtWindows` into `WinIcon`. - Move `EventLoopExtPumpEvents` and `PumpStatus` from platform module to `winit::event_loop::pump_events`. - Move `EventLoopExtRunOnDemand` from platform module to `winit::event_loop::run_on_demand`. +- Use `NamedKey`, `Code` and `Location` from the `keyboard-types` v0.8 crate. ### Removed