diff --git a/crates/bevy_input/Cargo.toml b/crates/bevy_input/Cargo.toml index 4292633430b63..28a8c57ee8009 100644 --- a/crates/bevy_input/Cargo.toml +++ b/crates/bevy_input/Cargo.toml @@ -25,6 +25,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.12.0", features = [ # other serde = { version = "1", features = ["derive"], optional = true } thiserror = "1.0" +smol_str = "0.2" [dev-dependencies] bevy = { path = "../../", version = "0.12.0" } diff --git a/crates/bevy_input/src/keyboard.rs b/crates/bevy_input/src/keyboard.rs index 8b7b784db259c..3465403871f45 100644 --- a/crates/bevy_input/src/keyboard.rs +++ b/crates/bevy_input/src/keyboard.rs @@ -73,6 +73,7 @@ use bevy_ecs::{ system::ResMut, }; use bevy_reflect::Reflect; +use smol_str::SmolStr; #[cfg(feature = "serialize")] use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; @@ -86,7 +87,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// /// The event is consumed inside of the [`keyboard_input_system`] /// to update the [`Input`](ButtonInput) resource. -#[derive(Event, Debug, Clone, Copy, PartialEq, Eq, Reflect)] +#[derive(Event, Debug, Clone, PartialEq, Eq, Reflect)] #[reflect(Debug, PartialEq)] #[cfg_attr( feature = "serialize", @@ -94,8 +95,10 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; reflect(Serialize, Deserialize) )] pub struct KeyboardInput { - /// The key code of the key. + /// The physical key code of the key. pub key_code: KeyCode, + /// The logical key of the input + pub logical_key: Key, /// The press state of the key. pub state: ButtonState, /// Window that received the input. @@ -650,3 +653,791 @@ pub enum KeyCode { /// General-purpose function key. F35, } + +/// Contains the platform-native logical key identifier, known as keysym. +/// +/// Exactly what that means differs from platform to platform, but the values are to some degree +/// tied to the currently active keyboard layout. The same key on the same keyboard may also report +/// different values on different platforms, which is one of the reasons this is a per-platform +/// enum. +/// +/// This enum is primarily used to store raw keysym when Winit doesn't map a given native logical +/// key identifier to a meaningful [`Key`] variant. This lets you use [`Key`], and let the user +/// define keybinds which work in the presence of identifiers we haven't mapped for you yet. +#[derive(Debug, Clone, Ord, PartialOrd, PartialEq, Eq, Hash, Reflect)] +#[reflect(Debug, Hash, PartialEq)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] +pub enum NativeKey { + /// Unidentified + Unidentified, + /// An Android "keycode", which is similar to a "virtual-key code" on Windows. + Android(u32), + /// A macOS "scancode". There does not appear to be any direct analogue to either keysyms or + /// "virtual-key" codes in macOS, so we report the scancode instead. + MacOS(u16), + /// A Windows "virtual-key code". + Windows(u16), + /// An XKB "keysym". + Xkb(u32), + /// A "key value string". + Web(SmolStr), +} + +/// The logical key code of a [`KeyboardInput`]. +/// +/// ## Technical +/// +/// Its values map 1 to 1 to winit's Key. +#[non_exhaustive] +#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Reflect)] +#[reflect(Debug, Hash, PartialEq)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] +pub enum Key { + /// A key string that corresponds to the character typed by the user, taking into account the + /// user’s current locale setting, and any system-level keyboard mapping overrides that are in + /// effect. + Character(SmolStr), + + /// This variant is used when the key cannot be translated to any other variant. + /// + /// The native key is provided (if available) in order to allow the user to specify keybindings + /// for keys which are not defined by this API, mainly through some sort of UI. + Unidentified(NativeKey), + + /// Contains the text representation of the dead-key when available. + /// + /// ## Platform-specific + /// - **Web:** Always contains `None` + Dead(Option), + + /// 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, + /// The SymbolLock key, only on web. + SymbolLock, + /// Legacy modifier key. Also called "Super" in certain places. + Meta, + /// Legacy modifier key. + Hyper, + /// Used to enable "super" 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. + /// + /// Note: In some contexts (e.g. the Web) this is referred to as the "Meta" key. + Super, + /// 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, + /// Used in text to insert a space between words. Usually located below the character keys. + Space, + /// 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, + /// The Cancel key. (on linux and web) + Cancel, + /// Show the application’s context menu. + /// This key is commonly found between the right `Super` 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, + /// The Execute key. + 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, + /// The Select key. + 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 + LogOff, + /// Toggle power state. (`KEYCODE_POWER`) + /// 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, + /// Initate the multi-candidate mode. + AllCandidates, + /// The Alphanumeric key (on linux/web) + 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, web only. + NextCandidate, + /// Accept current input method sequence without + /// conversion in IMEs. + NonConvert, + /// PreviousCandidate, web only. + PreviousCandidate, + /// IME PROCESS key + Process, + /// SingleCandidate + SingleCandidate, + /// Toggle between Hangul and English modes. + HangulMode, + /// HanjaMode + HanjaMode, + /// JunjaMode + 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 + LaunchMusicPlayer, + /// LaunchPhone + LaunchPhone, + /// LaunchScreenSaver + LaunchScreenSaver, + /// LaunchSpreadsheet + LaunchSpreadsheet, + /// LaunchWebBrowser + LaunchWebBrowser, + /// LaunchWebCam + LaunchWebCam, + /// LaunchWordProcessor + 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 + LastNumberRedial, + /// The Notification key. (`KEYCODE_NOTIFICATION`) + Notification, + /// Toggle between manner mode state: silent, vibrate, ring, ... (`KEYCODE_MANNER_MODE`) + MannerMode, + /// VoiceDial + 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, +} diff --git a/crates/bevy_input/src/lib.rs b/crates/bevy_input/src/lib.rs index c3f2b3af9e4f2..d08ed93ce890e 100644 --- a/crates/bevy_input/src/lib.rs +++ b/crates/bevy_input/src/lib.rs @@ -36,7 +36,7 @@ pub mod prelude { use bevy_app::prelude::*; use bevy_ecs::prelude::*; use bevy_reflect::Reflect; -use keyboard::{keyboard_input_system, KeyCode, KeyboardInput}; +use keyboard::{keyboard_input_system, Key, KeyCode, KeyboardInput, NativeKey, NativeKeyCode}; use mouse::{ mouse_button_input_system, MouseButton, MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel, @@ -114,7 +114,10 @@ impl Plugin for InputPlugin { // Register keyboard types app.register_type::() - .register_type::(); + .register_type::() + .register_type::() + .register_type::() + .register_type::(); // Register mouse types app.register_type::() diff --git a/crates/bevy_winit/src/converters.rs b/crates/bevy_winit/src/converters.rs index f7d2e8a209b6a..5cc2c03475528 100644 --- a/crates/bevy_winit/src/converters.rs +++ b/crates/bevy_winit/src/converters.rs @@ -7,6 +7,7 @@ use bevy_input::{ }; use bevy_math::Vec2; use bevy_window::{CursorIcon, EnabledButtons, WindowLevel, WindowTheme}; +use winit::keyboard::{Key, NamedKey, NativeKey}; pub fn convert_keyboard_input( keyboard_input: &winit::event::KeyEvent, @@ -15,6 +16,7 @@ pub fn convert_keyboard_input( KeyboardInput { state: convert_element_state(keyboard_input.state), key_code: convert_physical_key_code(keyboard_input.physical_key), + logical_key: convert_logical_key(&keyboard_input.logical_key), window, } } @@ -283,6 +285,348 @@ pub fn convert_physical_key_code(virtual_key_code: winit::keyboard::PhysicalKey) } } +pub fn convert_logical_key(logical_key_code: &winit::keyboard::Key) -> bevy_input::keyboard::Key { + match logical_key_code { + Key::Character(s) => bevy_input::keyboard::Key::Character(s.clone()), + Key::Unidentified(nk) => bevy_input::keyboard::Key::Unidentified(convert_native_key(nk)), + Key::Dead(c) => bevy_input::keyboard::Key::Dead(c.to_owned()), + Key::Named(NamedKey::Alt) => bevy_input::keyboard::Key::Alt, + Key::Named(NamedKey::AltGraph) => bevy_input::keyboard::Key::AltGraph, + Key::Named(NamedKey::CapsLock) => bevy_input::keyboard::Key::CapsLock, + Key::Named(NamedKey::Control) => bevy_input::keyboard::Key::Control, + Key::Named(NamedKey::Fn) => bevy_input::keyboard::Key::Fn, + Key::Named(NamedKey::FnLock) => bevy_input::keyboard::Key::FnLock, + Key::Named(NamedKey::NumLock) => bevy_input::keyboard::Key::NumLock, + Key::Named(NamedKey::ScrollLock) => bevy_input::keyboard::Key::ScrollLock, + Key::Named(NamedKey::Shift) => bevy_input::keyboard::Key::Shift, + Key::Named(NamedKey::Symbol) => bevy_input::keyboard::Key::Symbol, + Key::Named(NamedKey::SymbolLock) => bevy_input::keyboard::Key::SymbolLock, + Key::Named(NamedKey::Meta) => bevy_input::keyboard::Key::Meta, + Key::Named(NamedKey::Hyper) => bevy_input::keyboard::Key::Hyper, + Key::Named(NamedKey::Super) => bevy_input::keyboard::Key::Super, + Key::Named(NamedKey::Enter) => bevy_input::keyboard::Key::Enter, + Key::Named(NamedKey::Tab) => bevy_input::keyboard::Key::Tab, + Key::Named(NamedKey::Space) => bevy_input::keyboard::Key::Space, + Key::Named(NamedKey::ArrowDown) => bevy_input::keyboard::Key::ArrowDown, + Key::Named(NamedKey::ArrowLeft) => bevy_input::keyboard::Key::ArrowLeft, + Key::Named(NamedKey::ArrowRight) => bevy_input::keyboard::Key::ArrowRight, + Key::Named(NamedKey::ArrowUp) => bevy_input::keyboard::Key::ArrowUp, + Key::Named(NamedKey::End) => bevy_input::keyboard::Key::End, + Key::Named(NamedKey::Home) => bevy_input::keyboard::Key::Home, + Key::Named(NamedKey::PageDown) => bevy_input::keyboard::Key::PageDown, + Key::Named(NamedKey::PageUp) => bevy_input::keyboard::Key::PageUp, + Key::Named(NamedKey::Backspace) => bevy_input::keyboard::Key::Backspace, + Key::Named(NamedKey::Clear) => bevy_input::keyboard::Key::Clear, + Key::Named(NamedKey::Copy) => bevy_input::keyboard::Key::Copy, + Key::Named(NamedKey::CrSel) => bevy_input::keyboard::Key::CrSel, + Key::Named(NamedKey::Cut) => bevy_input::keyboard::Key::Cut, + Key::Named(NamedKey::Delete) => bevy_input::keyboard::Key::Delete, + Key::Named(NamedKey::EraseEof) => bevy_input::keyboard::Key::EraseEof, + Key::Named(NamedKey::ExSel) => bevy_input::keyboard::Key::ExSel, + Key::Named(NamedKey::Insert) => bevy_input::keyboard::Key::Insert, + Key::Named(NamedKey::Paste) => bevy_input::keyboard::Key::Paste, + Key::Named(NamedKey::Redo) => bevy_input::keyboard::Key::Redo, + Key::Named(NamedKey::Undo) => bevy_input::keyboard::Key::Undo, + Key::Named(NamedKey::Accept) => bevy_input::keyboard::Key::Accept, + Key::Named(NamedKey::Again) => bevy_input::keyboard::Key::Again, + Key::Named(NamedKey::Attn) => bevy_input::keyboard::Key::Attn, + Key::Named(NamedKey::Cancel) => bevy_input::keyboard::Key::Cancel, + Key::Named(NamedKey::ContextMenu) => bevy_input::keyboard::Key::ContextMenu, + Key::Named(NamedKey::Escape) => bevy_input::keyboard::Key::Escape, + Key::Named(NamedKey::Execute) => bevy_input::keyboard::Key::Execute, + Key::Named(NamedKey::Find) => bevy_input::keyboard::Key::Find, + Key::Named(NamedKey::Help) => bevy_input::keyboard::Key::Help, + Key::Named(NamedKey::Pause) => bevy_input::keyboard::Key::Pause, + Key::Named(NamedKey::Play) => bevy_input::keyboard::Key::Play, + Key::Named(NamedKey::Props) => bevy_input::keyboard::Key::Props, + Key::Named(NamedKey::Select) => bevy_input::keyboard::Key::Select, + Key::Named(NamedKey::ZoomIn) => bevy_input::keyboard::Key::ZoomIn, + Key::Named(NamedKey::ZoomOut) => bevy_input::keyboard::Key::ZoomOut, + Key::Named(NamedKey::BrightnessDown) => bevy_input::keyboard::Key::BrightnessDown, + Key::Named(NamedKey::BrightnessUp) => bevy_input::keyboard::Key::BrightnessUp, + Key::Named(NamedKey::Eject) => bevy_input::keyboard::Key::Eject, + Key::Named(NamedKey::LogOff) => bevy_input::keyboard::Key::LogOff, + Key::Named(NamedKey::Power) => bevy_input::keyboard::Key::Power, + Key::Named(NamedKey::PowerOff) => bevy_input::keyboard::Key::PowerOff, + Key::Named(NamedKey::PrintScreen) => bevy_input::keyboard::Key::PrintScreen, + Key::Named(NamedKey::Hibernate) => bevy_input::keyboard::Key::Hibernate, + Key::Named(NamedKey::Standby) => bevy_input::keyboard::Key::Standby, + Key::Named(NamedKey::WakeUp) => bevy_input::keyboard::Key::WakeUp, + Key::Named(NamedKey::AllCandidates) => bevy_input::keyboard::Key::AllCandidates, + Key::Named(NamedKey::Alphanumeric) => bevy_input::keyboard::Key::Alphanumeric, + Key::Named(NamedKey::CodeInput) => bevy_input::keyboard::Key::CodeInput, + Key::Named(NamedKey::Compose) => bevy_input::keyboard::Key::Compose, + Key::Named(NamedKey::Convert) => bevy_input::keyboard::Key::Convert, + Key::Named(NamedKey::FinalMode) => bevy_input::keyboard::Key::FinalMode, + Key::Named(NamedKey::GroupFirst) => bevy_input::keyboard::Key::GroupFirst, + Key::Named(NamedKey::GroupLast) => bevy_input::keyboard::Key::GroupLast, + Key::Named(NamedKey::GroupNext) => bevy_input::keyboard::Key::GroupNext, + Key::Named(NamedKey::GroupPrevious) => bevy_input::keyboard::Key::GroupPrevious, + Key::Named(NamedKey::ModeChange) => bevy_input::keyboard::Key::ModeChange, + Key::Named(NamedKey::NextCandidate) => bevy_input::keyboard::Key::NextCandidate, + Key::Named(NamedKey::NonConvert) => bevy_input::keyboard::Key::NonConvert, + Key::Named(NamedKey::PreviousCandidate) => bevy_input::keyboard::Key::PreviousCandidate, + Key::Named(NamedKey::Process) => bevy_input::keyboard::Key::Process, + Key::Named(NamedKey::SingleCandidate) => bevy_input::keyboard::Key::SingleCandidate, + Key::Named(NamedKey::HangulMode) => bevy_input::keyboard::Key::HangulMode, + Key::Named(NamedKey::HanjaMode) => bevy_input::keyboard::Key::HanjaMode, + Key::Named(NamedKey::JunjaMode) => bevy_input::keyboard::Key::JunjaMode, + Key::Named(NamedKey::Eisu) => bevy_input::keyboard::Key::Eisu, + Key::Named(NamedKey::Hankaku) => bevy_input::keyboard::Key::Hankaku, + Key::Named(NamedKey::Hiragana) => bevy_input::keyboard::Key::Hiragana, + Key::Named(NamedKey::HiraganaKatakana) => bevy_input::keyboard::Key::HiraganaKatakana, + Key::Named(NamedKey::KanaMode) => bevy_input::keyboard::Key::KanaMode, + Key::Named(NamedKey::KanjiMode) => bevy_input::keyboard::Key::KanjiMode, + Key::Named(NamedKey::Katakana) => bevy_input::keyboard::Key::Katakana, + Key::Named(NamedKey::Romaji) => bevy_input::keyboard::Key::Romaji, + Key::Named(NamedKey::Zenkaku) => bevy_input::keyboard::Key::Zenkaku, + Key::Named(NamedKey::ZenkakuHankaku) => bevy_input::keyboard::Key::ZenkakuHankaku, + Key::Named(NamedKey::Soft1) => bevy_input::keyboard::Key::Soft1, + Key::Named(NamedKey::Soft2) => bevy_input::keyboard::Key::Soft2, + Key::Named(NamedKey::Soft3) => bevy_input::keyboard::Key::Soft3, + Key::Named(NamedKey::Soft4) => bevy_input::keyboard::Key::Soft4, + Key::Named(NamedKey::ChannelDown) => bevy_input::keyboard::Key::ChannelDown, + Key::Named(NamedKey::ChannelUp) => bevy_input::keyboard::Key::ChannelUp, + Key::Named(NamedKey::Close) => bevy_input::keyboard::Key::Close, + Key::Named(NamedKey::MailForward) => bevy_input::keyboard::Key::MailForward, + Key::Named(NamedKey::MailReply) => bevy_input::keyboard::Key::MailReply, + Key::Named(NamedKey::MailSend) => bevy_input::keyboard::Key::MailSend, + Key::Named(NamedKey::MediaClose) => bevy_input::keyboard::Key::MediaClose, + Key::Named(NamedKey::MediaFastForward) => bevy_input::keyboard::Key::MediaFastForward, + Key::Named(NamedKey::MediaPause) => bevy_input::keyboard::Key::MediaPause, + Key::Named(NamedKey::MediaPlay) => bevy_input::keyboard::Key::MediaPlay, + Key::Named(NamedKey::MediaPlayPause) => bevy_input::keyboard::Key::MediaPlayPause, + Key::Named(NamedKey::MediaRecord) => bevy_input::keyboard::Key::MediaRecord, + Key::Named(NamedKey::MediaRewind) => bevy_input::keyboard::Key::MediaRewind, + Key::Named(NamedKey::MediaStop) => bevy_input::keyboard::Key::MediaStop, + Key::Named(NamedKey::MediaTrackNext) => bevy_input::keyboard::Key::MediaTrackNext, + Key::Named(NamedKey::MediaTrackPrevious) => bevy_input::keyboard::Key::MediaTrackPrevious, + Key::Named(NamedKey::New) => bevy_input::keyboard::Key::New, + Key::Named(NamedKey::Open) => bevy_input::keyboard::Key::Open, + Key::Named(NamedKey::Print) => bevy_input::keyboard::Key::Print, + Key::Named(NamedKey::Save) => bevy_input::keyboard::Key::Save, + Key::Named(NamedKey::SpellCheck) => bevy_input::keyboard::Key::SpellCheck, + Key::Named(NamedKey::Key11) => bevy_input::keyboard::Key::Key11, + Key::Named(NamedKey::Key12) => bevy_input::keyboard::Key::Key12, + Key::Named(NamedKey::AudioBalanceLeft) => bevy_input::keyboard::Key::AudioBalanceLeft, + Key::Named(NamedKey::AudioBalanceRight) => bevy_input::keyboard::Key::AudioBalanceRight, + Key::Named(NamedKey::AudioBassBoostDown) => bevy_input::keyboard::Key::AudioBassBoostDown, + Key::Named(NamedKey::AudioBassBoostToggle) => { + bevy_input::keyboard::Key::AudioBassBoostToggle + } + Key::Named(NamedKey::AudioBassBoostUp) => bevy_input::keyboard::Key::AudioBassBoostUp, + Key::Named(NamedKey::AudioFaderFront) => bevy_input::keyboard::Key::AudioFaderFront, + Key::Named(NamedKey::AudioFaderRear) => bevy_input::keyboard::Key::AudioFaderRear, + Key::Named(NamedKey::AudioSurroundModeNext) => { + bevy_input::keyboard::Key::AudioSurroundModeNext + } + Key::Named(NamedKey::AudioTrebleDown) => bevy_input::keyboard::Key::AudioTrebleDown, + Key::Named(NamedKey::AudioTrebleUp) => bevy_input::keyboard::Key::AudioTrebleUp, + Key::Named(NamedKey::AudioVolumeDown) => bevy_input::keyboard::Key::AudioVolumeDown, + Key::Named(NamedKey::AudioVolumeUp) => bevy_input::keyboard::Key::AudioVolumeUp, + Key::Named(NamedKey::AudioVolumeMute) => bevy_input::keyboard::Key::AudioVolumeMute, + Key::Named(NamedKey::MicrophoneToggle) => bevy_input::keyboard::Key::MicrophoneToggle, + Key::Named(NamedKey::MicrophoneVolumeDown) => { + bevy_input::keyboard::Key::MicrophoneVolumeDown + } + Key::Named(NamedKey::MicrophoneVolumeUp) => bevy_input::keyboard::Key::MicrophoneVolumeUp, + Key::Named(NamedKey::MicrophoneVolumeMute) => { + bevy_input::keyboard::Key::MicrophoneVolumeMute + } + Key::Named(NamedKey::SpeechCorrectionList) => { + bevy_input::keyboard::Key::SpeechCorrectionList + } + Key::Named(NamedKey::SpeechInputToggle) => bevy_input::keyboard::Key::SpeechInputToggle, + Key::Named(NamedKey::LaunchApplication1) => bevy_input::keyboard::Key::LaunchApplication1, + Key::Named(NamedKey::LaunchApplication2) => bevy_input::keyboard::Key::LaunchApplication2, + Key::Named(NamedKey::LaunchCalendar) => bevy_input::keyboard::Key::LaunchCalendar, + Key::Named(NamedKey::LaunchContacts) => bevy_input::keyboard::Key::LaunchContacts, + Key::Named(NamedKey::LaunchMail) => bevy_input::keyboard::Key::LaunchMail, + Key::Named(NamedKey::LaunchMediaPlayer) => bevy_input::keyboard::Key::LaunchMediaPlayer, + Key::Named(NamedKey::LaunchMusicPlayer) => bevy_input::keyboard::Key::LaunchMusicPlayer, + Key::Named(NamedKey::LaunchPhone) => bevy_input::keyboard::Key::LaunchPhone, + Key::Named(NamedKey::LaunchScreenSaver) => bevy_input::keyboard::Key::LaunchScreenSaver, + Key::Named(NamedKey::LaunchSpreadsheet) => bevy_input::keyboard::Key::LaunchSpreadsheet, + Key::Named(NamedKey::LaunchWebBrowser) => bevy_input::keyboard::Key::LaunchWebBrowser, + Key::Named(NamedKey::LaunchWebCam) => bevy_input::keyboard::Key::LaunchWebCam, + Key::Named(NamedKey::LaunchWordProcessor) => bevy_input::keyboard::Key::LaunchWordProcessor, + Key::Named(NamedKey::BrowserBack) => bevy_input::keyboard::Key::BrowserBack, + Key::Named(NamedKey::BrowserFavorites) => bevy_input::keyboard::Key::BrowserFavorites, + Key::Named(NamedKey::BrowserForward) => bevy_input::keyboard::Key::BrowserForward, + Key::Named(NamedKey::BrowserHome) => bevy_input::keyboard::Key::BrowserHome, + Key::Named(NamedKey::BrowserRefresh) => bevy_input::keyboard::Key::BrowserRefresh, + Key::Named(NamedKey::BrowserSearch) => bevy_input::keyboard::Key::BrowserSearch, + Key::Named(NamedKey::BrowserStop) => bevy_input::keyboard::Key::BrowserStop, + Key::Named(NamedKey::AppSwitch) => bevy_input::keyboard::Key::AppSwitch, + Key::Named(NamedKey::Call) => bevy_input::keyboard::Key::Call, + Key::Named(NamedKey::Camera) => bevy_input::keyboard::Key::Camera, + Key::Named(NamedKey::CameraFocus) => bevy_input::keyboard::Key::CameraFocus, + Key::Named(NamedKey::EndCall) => bevy_input::keyboard::Key::EndCall, + Key::Named(NamedKey::GoBack) => bevy_input::keyboard::Key::GoBack, + Key::Named(NamedKey::GoHome) => bevy_input::keyboard::Key::GoHome, + Key::Named(NamedKey::HeadsetHook) => bevy_input::keyboard::Key::HeadsetHook, + Key::Named(NamedKey::LastNumberRedial) => bevy_input::keyboard::Key::LastNumberRedial, + Key::Named(NamedKey::Notification) => bevy_input::keyboard::Key::Notification, + Key::Named(NamedKey::MannerMode) => bevy_input::keyboard::Key::MannerMode, + Key::Named(NamedKey::VoiceDial) => bevy_input::keyboard::Key::VoiceDial, + Key::Named(NamedKey::TV) => bevy_input::keyboard::Key::TV, + Key::Named(NamedKey::TV3DMode) => bevy_input::keyboard::Key::TV3DMode, + Key::Named(NamedKey::TVAntennaCable) => bevy_input::keyboard::Key::TVAntennaCable, + Key::Named(NamedKey::TVAudioDescription) => bevy_input::keyboard::Key::TVAudioDescription, + Key::Named(NamedKey::TVAudioDescriptionMixDown) => { + bevy_input::keyboard::Key::TVAudioDescriptionMixDown + } + Key::Named(NamedKey::TVAudioDescriptionMixUp) => { + bevy_input::keyboard::Key::TVAudioDescriptionMixUp + } + Key::Named(NamedKey::TVContentsMenu) => bevy_input::keyboard::Key::TVContentsMenu, + Key::Named(NamedKey::TVDataService) => bevy_input::keyboard::Key::TVDataService, + Key::Named(NamedKey::TVInput) => bevy_input::keyboard::Key::TVInput, + Key::Named(NamedKey::TVInputComponent1) => bevy_input::keyboard::Key::TVInputComponent1, + Key::Named(NamedKey::TVInputComponent2) => bevy_input::keyboard::Key::TVInputComponent2, + Key::Named(NamedKey::TVInputComposite1) => bevy_input::keyboard::Key::TVInputComposite1, + Key::Named(NamedKey::TVInputComposite2) => bevy_input::keyboard::Key::TVInputComposite2, + Key::Named(NamedKey::TVInputHDMI1) => bevy_input::keyboard::Key::TVInputHDMI1, + Key::Named(NamedKey::TVInputHDMI2) => bevy_input::keyboard::Key::TVInputHDMI2, + Key::Named(NamedKey::TVInputHDMI3) => bevy_input::keyboard::Key::TVInputHDMI3, + Key::Named(NamedKey::TVInputHDMI4) => bevy_input::keyboard::Key::TVInputHDMI4, + Key::Named(NamedKey::TVInputVGA1) => bevy_input::keyboard::Key::TVInputVGA1, + Key::Named(NamedKey::TVMediaContext) => bevy_input::keyboard::Key::TVMediaContext, + Key::Named(NamedKey::TVNetwork) => bevy_input::keyboard::Key::TVNetwork, + Key::Named(NamedKey::TVNumberEntry) => bevy_input::keyboard::Key::TVNumberEntry, + Key::Named(NamedKey::TVPower) => bevy_input::keyboard::Key::TVPower, + Key::Named(NamedKey::TVRadioService) => bevy_input::keyboard::Key::TVRadioService, + Key::Named(NamedKey::TVSatellite) => bevy_input::keyboard::Key::TVSatellite, + Key::Named(NamedKey::TVSatelliteBS) => bevy_input::keyboard::Key::TVSatelliteBS, + Key::Named(NamedKey::TVSatelliteCS) => bevy_input::keyboard::Key::TVSatelliteCS, + Key::Named(NamedKey::TVSatelliteToggle) => bevy_input::keyboard::Key::TVSatelliteToggle, + Key::Named(NamedKey::TVTerrestrialAnalog) => bevy_input::keyboard::Key::TVTerrestrialAnalog, + Key::Named(NamedKey::TVTerrestrialDigital) => { + bevy_input::keyboard::Key::TVTerrestrialDigital + } + Key::Named(NamedKey::TVTimer) => bevy_input::keyboard::Key::TVTimer, + Key::Named(NamedKey::AVRInput) => bevy_input::keyboard::Key::AVRInput, + Key::Named(NamedKey::AVRPower) => bevy_input::keyboard::Key::AVRPower, + Key::Named(NamedKey::ColorF0Red) => bevy_input::keyboard::Key::ColorF0Red, + Key::Named(NamedKey::ColorF1Green) => bevy_input::keyboard::Key::ColorF1Green, + Key::Named(NamedKey::ColorF2Yellow) => bevy_input::keyboard::Key::ColorF2Yellow, + Key::Named(NamedKey::ColorF3Blue) => bevy_input::keyboard::Key::ColorF3Blue, + Key::Named(NamedKey::ColorF4Grey) => bevy_input::keyboard::Key::ColorF4Grey, + Key::Named(NamedKey::ColorF5Brown) => bevy_input::keyboard::Key::ColorF5Brown, + Key::Named(NamedKey::ClosedCaptionToggle) => bevy_input::keyboard::Key::ClosedCaptionToggle, + Key::Named(NamedKey::Dimmer) => bevy_input::keyboard::Key::Dimmer, + Key::Named(NamedKey::DisplaySwap) => bevy_input::keyboard::Key::DisplaySwap, + Key::Named(NamedKey::DVR) => bevy_input::keyboard::Key::DVR, + Key::Named(NamedKey::Exit) => bevy_input::keyboard::Key::Exit, + Key::Named(NamedKey::FavoriteClear0) => bevy_input::keyboard::Key::FavoriteClear0, + Key::Named(NamedKey::FavoriteClear1) => bevy_input::keyboard::Key::FavoriteClear1, + Key::Named(NamedKey::FavoriteClear2) => bevy_input::keyboard::Key::FavoriteClear2, + Key::Named(NamedKey::FavoriteClear3) => bevy_input::keyboard::Key::FavoriteClear3, + Key::Named(NamedKey::FavoriteRecall0) => bevy_input::keyboard::Key::FavoriteRecall0, + Key::Named(NamedKey::FavoriteRecall1) => bevy_input::keyboard::Key::FavoriteRecall1, + Key::Named(NamedKey::FavoriteRecall2) => bevy_input::keyboard::Key::FavoriteRecall2, + Key::Named(NamedKey::FavoriteRecall3) => bevy_input::keyboard::Key::FavoriteRecall3, + Key::Named(NamedKey::FavoriteStore0) => bevy_input::keyboard::Key::FavoriteStore0, + Key::Named(NamedKey::FavoriteStore1) => bevy_input::keyboard::Key::FavoriteStore1, + Key::Named(NamedKey::FavoriteStore2) => bevy_input::keyboard::Key::FavoriteStore2, + Key::Named(NamedKey::FavoriteStore3) => bevy_input::keyboard::Key::FavoriteStore3, + Key::Named(NamedKey::Guide) => bevy_input::keyboard::Key::Guide, + Key::Named(NamedKey::GuideNextDay) => bevy_input::keyboard::Key::GuideNextDay, + Key::Named(NamedKey::GuidePreviousDay) => bevy_input::keyboard::Key::GuidePreviousDay, + Key::Named(NamedKey::Info) => bevy_input::keyboard::Key::Info, + Key::Named(NamedKey::InstantReplay) => bevy_input::keyboard::Key::InstantReplay, + Key::Named(NamedKey::Link) => bevy_input::keyboard::Key::Link, + Key::Named(NamedKey::ListProgram) => bevy_input::keyboard::Key::ListProgram, + Key::Named(NamedKey::LiveContent) => bevy_input::keyboard::Key::LiveContent, + Key::Named(NamedKey::Lock) => bevy_input::keyboard::Key::Lock, + Key::Named(NamedKey::MediaApps) => bevy_input::keyboard::Key::MediaApps, + Key::Named(NamedKey::MediaAudioTrack) => bevy_input::keyboard::Key::MediaAudioTrack, + Key::Named(NamedKey::MediaLast) => bevy_input::keyboard::Key::MediaLast, + Key::Named(NamedKey::MediaSkipBackward) => bevy_input::keyboard::Key::MediaSkipBackward, + Key::Named(NamedKey::MediaSkipForward) => bevy_input::keyboard::Key::MediaSkipForward, + Key::Named(NamedKey::MediaStepBackward) => bevy_input::keyboard::Key::MediaStepBackward, + Key::Named(NamedKey::MediaStepForward) => bevy_input::keyboard::Key::MediaStepForward, + Key::Named(NamedKey::MediaTopMenu) => bevy_input::keyboard::Key::MediaTopMenu, + Key::Named(NamedKey::NavigateIn) => bevy_input::keyboard::Key::NavigateIn, + Key::Named(NamedKey::NavigateNext) => bevy_input::keyboard::Key::NavigateNext, + Key::Named(NamedKey::NavigateOut) => bevy_input::keyboard::Key::NavigateOut, + Key::Named(NamedKey::NavigatePrevious) => bevy_input::keyboard::Key::NavigatePrevious, + Key::Named(NamedKey::NextFavoriteChannel) => bevy_input::keyboard::Key::NextFavoriteChannel, + Key::Named(NamedKey::NextUserProfile) => bevy_input::keyboard::Key::NextUserProfile, + Key::Named(NamedKey::OnDemand) => bevy_input::keyboard::Key::OnDemand, + Key::Named(NamedKey::Pairing) => bevy_input::keyboard::Key::Pairing, + Key::Named(NamedKey::PinPDown) => bevy_input::keyboard::Key::PinPDown, + Key::Named(NamedKey::PinPMove) => bevy_input::keyboard::Key::PinPMove, + Key::Named(NamedKey::PinPToggle) => bevy_input::keyboard::Key::PinPToggle, + Key::Named(NamedKey::PinPUp) => bevy_input::keyboard::Key::PinPUp, + Key::Named(NamedKey::PlaySpeedDown) => bevy_input::keyboard::Key::PlaySpeedDown, + Key::Named(NamedKey::PlaySpeedReset) => bevy_input::keyboard::Key::PlaySpeedReset, + Key::Named(NamedKey::PlaySpeedUp) => bevy_input::keyboard::Key::PlaySpeedUp, + Key::Named(NamedKey::RandomToggle) => bevy_input::keyboard::Key::RandomToggle, + Key::Named(NamedKey::RcLowBattery) => bevy_input::keyboard::Key::RcLowBattery, + Key::Named(NamedKey::RecordSpeedNext) => bevy_input::keyboard::Key::RecordSpeedNext, + Key::Named(NamedKey::RfBypass) => bevy_input::keyboard::Key::RfBypass, + Key::Named(NamedKey::ScanChannelsToggle) => bevy_input::keyboard::Key::ScanChannelsToggle, + Key::Named(NamedKey::ScreenModeNext) => bevy_input::keyboard::Key::ScreenModeNext, + Key::Named(NamedKey::Settings) => bevy_input::keyboard::Key::Settings, + Key::Named(NamedKey::SplitScreenToggle) => bevy_input::keyboard::Key::SplitScreenToggle, + Key::Named(NamedKey::STBInput) => bevy_input::keyboard::Key::STBInput, + Key::Named(NamedKey::STBPower) => bevy_input::keyboard::Key::STBPower, + Key::Named(NamedKey::Subtitle) => bevy_input::keyboard::Key::Subtitle, + Key::Named(NamedKey::Teletext) => bevy_input::keyboard::Key::Teletext, + Key::Named(NamedKey::VideoModeNext) => bevy_input::keyboard::Key::VideoModeNext, + Key::Named(NamedKey::Wink) => bevy_input::keyboard::Key::Wink, + Key::Named(NamedKey::ZoomToggle) => bevy_input::keyboard::Key::ZoomToggle, + Key::Named(NamedKey::F1) => bevy_input::keyboard::Key::F1, + Key::Named(NamedKey::F2) => bevy_input::keyboard::Key::F2, + Key::Named(NamedKey::F3) => bevy_input::keyboard::Key::F3, + Key::Named(NamedKey::F4) => bevy_input::keyboard::Key::F4, + Key::Named(NamedKey::F5) => bevy_input::keyboard::Key::F5, + Key::Named(NamedKey::F6) => bevy_input::keyboard::Key::F6, + Key::Named(NamedKey::F7) => bevy_input::keyboard::Key::F7, + Key::Named(NamedKey::F8) => bevy_input::keyboard::Key::F8, + Key::Named(NamedKey::F9) => bevy_input::keyboard::Key::F9, + Key::Named(NamedKey::F10) => bevy_input::keyboard::Key::F10, + Key::Named(NamedKey::F11) => bevy_input::keyboard::Key::F11, + Key::Named(NamedKey::F12) => bevy_input::keyboard::Key::F12, + Key::Named(NamedKey::F13) => bevy_input::keyboard::Key::F13, + Key::Named(NamedKey::F14) => bevy_input::keyboard::Key::F14, + Key::Named(NamedKey::F15) => bevy_input::keyboard::Key::F15, + Key::Named(NamedKey::F16) => bevy_input::keyboard::Key::F16, + Key::Named(NamedKey::F17) => bevy_input::keyboard::Key::F17, + Key::Named(NamedKey::F18) => bevy_input::keyboard::Key::F18, + Key::Named(NamedKey::F19) => bevy_input::keyboard::Key::F19, + Key::Named(NamedKey::F20) => bevy_input::keyboard::Key::F20, + Key::Named(NamedKey::F21) => bevy_input::keyboard::Key::F21, + Key::Named(NamedKey::F22) => bevy_input::keyboard::Key::F22, + Key::Named(NamedKey::F23) => bevy_input::keyboard::Key::F23, + Key::Named(NamedKey::F24) => bevy_input::keyboard::Key::F24, + Key::Named(NamedKey::F25) => bevy_input::keyboard::Key::F25, + Key::Named(NamedKey::F26) => bevy_input::keyboard::Key::F26, + Key::Named(NamedKey::F27) => bevy_input::keyboard::Key::F27, + Key::Named(NamedKey::F28) => bevy_input::keyboard::Key::F28, + Key::Named(NamedKey::F29) => bevy_input::keyboard::Key::F29, + Key::Named(NamedKey::F30) => bevy_input::keyboard::Key::F30, + Key::Named(NamedKey::F31) => bevy_input::keyboard::Key::F31, + Key::Named(NamedKey::F32) => bevy_input::keyboard::Key::F32, + Key::Named(NamedKey::F33) => bevy_input::keyboard::Key::F33, + Key::Named(NamedKey::F34) => bevy_input::keyboard::Key::F34, + Key::Named(NamedKey::F35) => bevy_input::keyboard::Key::F35, + _ => todo!(), + } +} + +pub fn convert_native_key(native_key: &NativeKey) -> bevy_input::keyboard::NativeKey { + match native_key { + NativeKey::Unidentified => bevy_input::keyboard::NativeKey::Unidentified, + NativeKey::Android(v) => bevy_input::keyboard::NativeKey::Android(*v), + NativeKey::MacOS(v) => bevy_input::keyboard::NativeKey::MacOS(*v), + NativeKey::Windows(v) => bevy_input::keyboard::NativeKey::Windows(*v), + NativeKey::Xkb(v) => bevy_input::keyboard::NativeKey::Xkb(*v), + NativeKey::Web(v) => bevy_input::keyboard::NativeKey::Web(v.clone()), + } +} + pub fn convert_cursor_icon(cursor_icon: CursorIcon) -> winit::window::CursorIcon { match cursor_icon { CursorIcon::Crosshair => winit::window::CursorIcon::Crosshair,