From 861091349c8c774f29780c7d01bde8b0ca748ddf Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sun, 15 Oct 2023 10:05:06 +0100 Subject: [PATCH] Split enum Key into Key, Action --- examples/control_flow.rs | 4 +- examples/cursor_grab.rs | 4 +- examples/fullscreen.rs | 4 +- examples/ime.rs | 6 +- examples/multithreaded.rs | 18 +- examples/multiwindow.rs | 4 +- examples/window_resize_increments.rs | 16 +- examples/window_tabbing.rs | 6 +- src/event.rs | 2 +- src/keyboard.rs | 191 +++--- src/platform_impl/android/keycodes.rs | 330 +++++----- src/platform_impl/linux/common/keymap.rs | 640 +++++++++---------- src/platform_impl/macos/event.rs | 108 ++-- src/platform_impl/macos/view.rs | 26 +- src/platform_impl/web/keyboard.rs | 622 +++++++++--------- src/platform_impl/web/web_sys/event.rs | 8 +- src/platform_impl/windows/keyboard.rs | 11 +- src/platform_impl/windows/keyboard_layout.rs | 222 +++---- 18 files changed, 1101 insertions(+), 1121 deletions(-) diff --git a/examples/control_flow.rs b/examples/control_flow.rs index b7537af048..9ee9ca52be 100644 --- a/examples/control_flow.rs +++ b/examples/control_flow.rs @@ -10,7 +10,7 @@ use simple_logger::SimpleLogger; use winit::{ event::{ElementState, Event, KeyEvent, WindowEvent}, event_loop::{ControlFlow, EventLoop}, - keyboard::Key, + keyboard::{Action, Key}, window::WindowBuilder, }; @@ -88,7 +88,7 @@ fn main() -> Result<(), impl std::error::Error> { request_redraw = !request_redraw; println!("\nrequest_redraw: {request_redraw}\n"); } - Key::Escape => { + Key::Action(Action::Escape) => { close_requested = true; } _ => (), diff --git a/examples/cursor_grab.rs b/examples/cursor_grab.rs index 4bbfea0b1f..8330fc569f 100644 --- a/examples/cursor_grab.rs +++ b/examples/cursor_grab.rs @@ -4,7 +4,7 @@ use simple_logger::SimpleLogger; use winit::{ event::{DeviceEvent, ElementState, Event, KeyEvent, WindowEvent}, event_loop::EventLoop, - keyboard::{Key, ModifiersState}, + keyboard::{Action, Key, ModifiersState}, window::{CursorGrabMode, WindowBuilder}, }; @@ -35,7 +35,7 @@ fn main() -> Result<(), impl std::error::Error> { .. } => { let result = match key { - Key::Escape => { + Key::Action(Action::Escape) => { elwt.exit(); Ok(()) } diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index 4195e99e56..feae7cc42f 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -4,7 +4,7 @@ use simple_logger::SimpleLogger; use winit::dpi::PhysicalSize; use winit::event::{ElementState, Event, KeyEvent, WindowEvent}; use winit::event_loop::EventLoop; -use winit::keyboard::Key; +use winit::keyboard::{Action, Key}; use winit::window::{Fullscreen, WindowBuilder}; #[cfg(target_os = "macos")] @@ -65,7 +65,7 @@ fn main() -> Result<(), impl std::error::Error> { }, .. } => match key { - Key::Escape => elwt.exit(), + Key::Action(Action::Escape) => elwt.exit(), // WARNING: Consider using `key_without_modifers()` if available on your platform. // See the `key_binding` example Key::Character(ch) => match ch.to_lowercase().as_str() { diff --git a/examples/ime.rs b/examples/ime.rs index aacc559e54..623f2c4f2b 100644 --- a/examples/ime.rs +++ b/examples/ime.rs @@ -6,7 +6,7 @@ use winit::{ dpi::{PhysicalPosition, PhysicalSize}, event::{ElementState, Event, Ime, WindowEvent}, event_loop::EventLoop, - keyboard::Key, + keyboard::Action, window::{ImePurpose, WindowBuilder}, }; @@ -69,12 +69,12 @@ fn main() -> Result<(), impl std::error::Error> { WindowEvent::KeyboardInput { event, .. } => { println!("key: {event:?}"); - if event.state == ElementState::Pressed && event.logical_key == Key::F2 { + if event.state == ElementState::Pressed && event.logical_key == Action::F2 { ime_allowed = !ime_allowed; window.set_ime_allowed(ime_allowed); println!("\nIME allowed: {ime_allowed}\n"); } - if event.state == ElementState::Pressed && event.logical_key == Key::F3 { + if event.state == ElementState::Pressed && event.logical_key == Action::F3 { ime_purpose = match ime_purpose { ImePurpose::Normal => ImePurpose::Password, ImePurpose::Password => ImePurpose::Terminal, diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index 49ddb50a55..fc7145a619 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -9,7 +9,7 @@ fn main() -> Result<(), impl std::error::Error> { dpi::{PhysicalPosition, PhysicalSize, Position, Size}, event::{ElementState, Event, KeyEvent, WindowEvent}, event_loop::EventLoop, - keyboard::{Key, ModifiersState}, + keyboard::{Action, Key, ModifiersState}, window::{CursorGrabMode, CursorIcon, Fullscreen, WindowBuilder, WindowLevel}, }; @@ -65,17 +65,17 @@ fn main() -> Result<(), impl std::error::Error> { }, .. } => { - use Key::{ArrowLeft, ArrowRight}; + use Action::{ArrowLeft, ArrowRight}; window.set_title(&format!("{key:?}")); let state = !modifiers.shift_key(); match key { // Cycle through video modes - Key::ArrowRight | Key::ArrowLeft => { - video_mode_id = match key { - ArrowLeft => video_mode_id.saturating_sub(1), - ArrowRight => (video_modes.len() - 1).min(video_mode_id + 1), - _ => unreachable!(), - }; + Key::Action(ArrowRight) | Key::Action(ArrowLeft) => { + if key == ArrowLeft { + video_mode_id = video_mode_id.saturating_sub(1); + } else if key == ArrowRight { + video_mode_id = (video_modes.len() - 1).min(video_mode_id + 1); + } println!("Picking video mode: {}", video_modes[video_mode_id]); } // WARNING: Consider using `key_without_modifers()` if available on your platform. @@ -185,7 +185,7 @@ fn main() -> Result<(), impl std::error::Error> { event: KeyEvent { state: ElementState::Released, - logical_key: Key::Escape, + logical_key: Key::Action(Action::Escape), .. }, .. diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs index 38532a8fe4..f0377df4cb 100644 --- a/examples/multiwindow.rs +++ b/examples/multiwindow.rs @@ -6,7 +6,7 @@ use simple_logger::SimpleLogger; use winit::{ event::{ElementState, Event, WindowEvent}, event_loop::EventLoop, - keyboard::Key, + keyboard::{Action, Key}, window::Window, }; @@ -44,7 +44,7 @@ fn main() -> Result<(), impl std::error::Error> { is_synthetic: false, .. } if event.state == ElementState::Pressed => match event.logical_key { - Key::Escape => elwt.exit(), + Key::Action(Action::Escape) => elwt.exit(), Key::Character(c) if c == "n" || c == "N" => { let window = Window::new(elwt).unwrap(); println!("Opened a new window: {:?}", window.id()); diff --git a/examples/window_resize_increments.rs b/examples/window_resize_increments.rs index 6eba170cda..59e1bb368e 100644 --- a/examples/window_resize_increments.rs +++ b/examples/window_resize_increments.rs @@ -2,9 +2,9 @@ use log::debug; use simple_logger::SimpleLogger; use winit::{ dpi::LogicalSize, - event::{ElementState, Event, KeyEvent, WindowEvent}, + event::{ElementState, Event, WindowEvent}, event_loop::EventLoop, - keyboard::Key, + keyboard::Action, window::WindowBuilder, }; @@ -27,15 +27,9 @@ fn main() -> Result<(), impl std::error::Error> { event_loop.run(move |event, elwt| match event { Event::WindowEvent { event, window_id } if window_id == window.id() => match event { WindowEvent::CloseRequested => elwt.exit(), - WindowEvent::KeyboardInput { - event: - KeyEvent { - logical_key: Key::Space, - state: ElementState::Released, - .. - }, - .. - } => { + WindowEvent::KeyboardInput { event, .. } + if event.logical_key == Action::Space && event.state == ElementState::Released => + { has_increments = !has_increments; let new_increments = match window.resize_increments() { diff --git a/examples/window_tabbing.rs b/examples/window_tabbing.rs index a99683236b..cea9a62318 100644 --- a/examples/window_tabbing.rs +++ b/examples/window_tabbing.rs @@ -9,7 +9,7 @@ use simple_logger::SimpleLogger; use winit::{ event::{ElementState, Event, KeyEvent, WindowEvent}, event_loop::EventLoop, - keyboard::Key, + keyboard::{Action, Key}, platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS}, window::{Window, WindowBuilder}, }; @@ -70,10 +70,10 @@ fn main() -> Result<(), impl std::error::Error> { Key::Character("w") => { let _ = windows.remove(&window_id); } - Key::ArrowRight => { + Key::Action(Action::ArrowRight) => { windows.get(&window_id).unwrap().select_next_tab(); } - Key::ArrowLeft => { + Key::Action(Action::ArrowLeft) => { windows.get(&window_id).unwrap().select_previous_tab(); } Key::Character(ch) => { diff --git a/src/event.rs b/src/event.rs index 3bf1213106..a20a79d27b 100644 --- a/src/event.rs +++ b/src/event.rs @@ -743,7 +743,7 @@ pub struct KeyEvent { /// An additional difference from `logical_key` is that /// this field stores the text representation of any key /// that has such a representation. For example when - /// `logical_key` is `Key::Enter`, this field is `Some("\r")`. + /// `logical_key` is `Key::Action(Action::Enter)`, this field is `Some("\r")`. /// /// This is `None` if the current keypress cannot /// be interpreted as text. diff --git a/src/keyboard.rs b/src/keyboard.rs index c21d9e4991..38a3e4bbf3 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -734,7 +734,7 @@ pub enum KeyCode { F35, } -/// Key represents the meaning of a keypress. +/// Action represents the meaning of a keypress. /// /// This mostly conforms to the UI Events Specification's [`KeyboardEvent.key`] with a few /// exceptions: @@ -742,32 +742,12 @@ pub enum KeyCode { /// another key which the specification calls `Super`. That does not exist here.) /// - The `Space` variant here, can be identified by the character it generates in the /// specificaiton. -/// - The `Unidentified` variant here, can still identifiy a key through it's `NativeKeyCode`. -/// - The `Dead` variant here, can specify the character which is inserted when pressing the -/// dead-key twice. /// /// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/ #[non_exhaustive] -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(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(Str), - - /// 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), - +pub enum Action { /// The `Alt` (Alternative) key. /// /// This key enables the alternate modifier function for interpreting concurrent or subsequent @@ -1471,6 +1451,47 @@ pub enum Key { F35, } +/// Key represents the meaning of a keypress. +/// +/// This is a superset of the UI Events Specification's [`KeyboardEvent.key`] with +/// additions: +/// - All simple variants are wrapped under the `Action` variant +/// - The `Unidentified` variant here, can still identifiy a key through it's `NativeKeyCode`. +/// - The `Dead` variant here, can specify the character which is inserted when pressing the +/// dead-key twice. +/// +/// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/ +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum Key { + /// A simple (unparameterised) action + Action(Action), + + /// 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(Str), + + /// 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), +} + +impl From for Key { + #[inline] + fn from(action: Action) -> Self { + Key::Action(action) + } +} + impl From for Key { #[inline] fn from(code: NativeKey) -> Self { @@ -1478,6 +1499,16 @@ impl From for Key { } } +impl PartialEq for Key { + #[inline] + fn eq(&self, rhs: &Action) -> bool { + match self { + Key::Action(ref a) => a == rhs, + _ => false, + } + } +} + impl> PartialEq for Key { #[inline] fn eq(&self, rhs: &str) -> bool { @@ -1512,83 +1543,39 @@ impl PartialEq> for NativeKey { } } -macro_rules! map_match { - ( - $to_match:expr, - // Custom match arms - { $( $from:pat => $to:expr ),* }, - // The enum's name - $prefix:path, - // Trivial match arms for unit variants - { $( $t:tt ),* }) => { - match $to_match { - $( $from => $to, )* - $( Key::$t => Key::$t, )* - } - }; -} - impl Key { /// Convert `Key::Character(SmolStr)` to `Key::Character(&str)` so you can more easily match on /// `Key`. All other variants remain unchanged. pub fn as_ref(&self) -> Key<&str> { - map_match!( - self, - { - Key::Character(ch) => Key::Character(ch.as_str()), - Key::Dead(d) => Key::Dead(*d), - Key::Unidentified(u) => Key::Unidentified(u.clone()) - }, - Key, - { - Alt, AltGraph, CapsLock, Control, Fn, FnLock, NumLock, ScrollLock, Shift, Symbol, - SymbolLock, Meta, Hyper, Super, Enter, Tab, Space, ArrowDown, ArrowLeft, - ArrowRight, ArrowUp, End, Home, PageDown, PageUp, Backspace, Clear, Copy, CrSel, - Cut, Delete, EraseEof, ExSel, Insert, Paste, Redo, Undo, Accept, Again, Attn, - Cancel, ContextMenu, Escape, Execute, Find, Help, Pause, Play, Props, Select, - ZoomIn, ZoomOut, BrightnessDown, BrightnessUp, Eject, LogOff, Power, PowerOff, - PrintScreen, Hibernate, Standby, WakeUp, AllCandidates, Alphanumeric, CodeInput, - Compose, Convert, FinalMode, GroupFirst, GroupLast, GroupNext, GroupPrevious, - ModeChange, NextCandidate, NonConvert, PreviousCandidate, Process, SingleCandidate, - HangulMode, HanjaMode, JunjaMode, Eisu, Hankaku, Hiragana, HiraganaKatakana, - KanaMode, KanjiMode, Katakana, Romaji, Zenkaku, ZenkakuHankaku, Soft1, Soft2, - Soft3, Soft4, ChannelDown, ChannelUp, Close, MailForward, MailReply, MailSend, - MediaClose, MediaFastForward, MediaPause, MediaPlay, MediaPlayPause, MediaRecord, - MediaRewind, MediaStop, MediaTrackNext, MediaTrackPrevious, New, Open, Print, Save, - SpellCheck, Key11, Key12, AudioBalanceLeft, AudioBalanceRight, AudioBassBoostDown, - AudioBassBoostToggle, AudioBassBoostUp, AudioFaderFront, AudioFaderRear, - AudioSurroundModeNext, AudioTrebleDown, AudioTrebleUp, AudioVolumeDown, - AudioVolumeUp, AudioVolumeMute, MicrophoneToggle, MicrophoneVolumeDown, - MicrophoneVolumeUp, MicrophoneVolumeMute, SpeechCorrectionList, SpeechInputToggle, - LaunchApplication1, LaunchApplication2, LaunchCalendar, LaunchContacts, LaunchMail, - LaunchMediaPlayer, LaunchMusicPlayer, LaunchPhone, LaunchScreenSaver, - LaunchSpreadsheet, LaunchWebBrowser, LaunchWebCam, LaunchWordProcessor, - BrowserBack, BrowserFavorites, BrowserForward, BrowserHome, BrowserRefresh, - BrowserSearch, BrowserStop, AppSwitch, Call, Camera, CameraFocus, EndCall, GoBack, - GoHome, HeadsetHook, LastNumberRedial, Notification, MannerMode, VoiceDial, TV, - TV3DMode, TVAntennaCable, TVAudioDescription, TVAudioDescriptionMixDown, - TVAudioDescriptionMixUp, TVContentsMenu, TVDataService, TVInput, TVInputComponent1, - TVInputComponent2, TVInputComposite1, TVInputComposite2, TVInputHDMI1, - TVInputHDMI2, TVInputHDMI3, TVInputHDMI4, TVInputVGA1, TVMediaContext, TVNetwork, - TVNumberEntry, TVPower, TVRadioService, TVSatellite, TVSatelliteBS, TVSatelliteCS, - TVSatelliteToggle, TVTerrestrialAnalog, TVTerrestrialDigital, TVTimer, AVRInput, - AVRPower, ColorF0Red, ColorF1Green, ColorF2Yellow, ColorF3Blue, ColorF4Grey, - ColorF5Brown, ClosedCaptionToggle, Dimmer, DisplaySwap, DVR, Exit, FavoriteClear0, - FavoriteClear1, FavoriteClear2, FavoriteClear3, FavoriteRecall0, FavoriteRecall1, - FavoriteRecall2, FavoriteRecall3, FavoriteStore0, FavoriteStore1, FavoriteStore2, - FavoriteStore3, Guide, GuideNextDay, GuidePreviousDay, Info, InstantReplay, Link, - ListProgram, LiveContent, Lock, MediaApps, MediaAudioTrack, MediaLast, - MediaSkipBackward, MediaSkipForward, MediaStepBackward, MediaStepForward, - MediaTopMenu, NavigateIn, NavigateNext, NavigateOut, NavigatePrevious, - NextFavoriteChannel, NextUserProfile, OnDemand, Pairing, PinPDown, PinPMove, - PinPToggle, PinPUp, PlaySpeedDown, PlaySpeedReset, PlaySpeedUp, RandomToggle, - RcLowBattery, RecordSpeedNext, RfBypass, ScanChannelsToggle, ScreenModeNext, - Settings, SplitScreenToggle, STBInput, STBPower, Subtitle, Teletext, VideoModeNext, - Wink, ZoomToggle, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, - F16, F17, F18, F19, F20, F21, F22, F23, F24, F25, F26, F27, F28, F29, F30, F31, - F32, F33, F34, F35 - } - ) + match self { + Key::Action(a) => Key::Action(*a), + Key::Character(ch) => Key::Character(ch.as_str()), + Key::Dead(d) => Key::Dead(*d), + Key::Unidentified(u) => Key::Unidentified(u.clone()), + } + } +} + +impl Action { + /// Convert an action to its approximate textual equivalent. + /// + /// # Examples + /// + /// ``` + /// use winit::keyboard::Action; + /// + /// assert_eq!(Action::Enter.to_text(), Some("\r")); + /// assert_eq!(Action::F20.to_text(), None); + /// ``` + pub fn to_text(&self) -> Option<&str> { + match self { + Action::Enter => Some("\r"), + Action::Backspace => Some("\x08"), + Action::Tab => Some("\t"), + Action::Space => Some(" "), + Action::Escape => Some("\x1b"), + _ => None, + } } } @@ -1598,20 +1585,16 @@ impl Key { /// # Examples /// /// ``` - /// use winit::keyboard::Key; + /// use winit::keyboard::{Action, Key}; /// /// assert_eq!(Key::Character("a".into()).to_text(), Some("a")); - /// assert_eq!(Key::Enter.to_text(), Some("\r")); - /// assert_eq!(Key::F20.to_text(), None); + /// assert_eq!(Key::Action(Action::Enter).to_text(), Some("\r")); + /// assert_eq!(Key::Action(Action::F20).to_text(), None); /// ``` pub fn to_text(&self) -> Option<&str> { match self { + Key::Action(action) => action.to_text(), Key::Character(ch) => Some(ch.as_str()), - Key::Enter => Some("\r"), - Key::Backspace => Some("\x08"), - Key::Tab => Some("\t"), - Key::Space => Some(" "), - Key::Escape => Some("\x1b"), _ => None, } } diff --git a/src/platform_impl/android/keycodes.rs b/src/platform_impl/android/keycodes.rs index 41b2902e1f..719f704732 100644 --- a/src/platform_impl/android/keycodes.rs +++ b/src/platform_impl/android/keycodes.rs @@ -3,7 +3,7 @@ use android_activity::{ AndroidApp, }; -use crate::keyboard::{Key, KeyCode, KeyLocation, NativeKey, NativeKeyCode, PhysicalKey}; +use crate::keyboard::{Action, Key, KeyCode, KeyLocation, NativeKey, NativeKeyCode, PhysicalKey}; pub fn to_physical_key(keycode: Keycode) -> PhysicalKey { PhysicalKey::Code(match keycode { @@ -231,10 +231,10 @@ pub fn to_logical(key_char: Option, keycode: Keycode) -> Key { None | Some(KeyMapChar::None) => match keycode { // Using `BrowserHome` instead of `GoHome` according to // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - Home => Key::BrowserHome, - Back => Key::BrowserBack, - Call => Key::Call, - Endcall => Key::EndCall, + Home => Key::Action(Action::BrowserHome), + Back => Key::Action(Action::BrowserBack), + Call => Key::Action(Action::Call), + Endcall => Key::Action(Action::EndCall), //------------------------------------------------------------------------------- // These should be redundant because they should have already been matched @@ -291,81 +291,81 @@ pub fn to_logical(key_char: Option, keycode: Keycode) -> Key { At => Key::Character("@".into()), Plus => Key::Character("+".into()), //------------------------------------------------------------------------------- - DpadUp => Key::ArrowUp, - DpadDown => Key::ArrowDown, - DpadLeft => Key::ArrowLeft, - DpadRight => Key::ArrowRight, - DpadCenter => Key::Enter, - - VolumeUp => Key::AudioVolumeUp, - VolumeDown => Key::AudioVolumeDown, - Power => Key::Power, - Camera => Key::Camera, - Clear => Key::Clear, - - AltLeft => Key::Alt, - AltRight => Key::Alt, - ShiftLeft => Key::Shift, - ShiftRight => Key::Shift, - Tab => Key::Tab, - Space => Key::Space, - Sym => Key::Symbol, - Explorer => Key::LaunchWebBrowser, - Envelope => Key::LaunchMail, - Enter => Key::Enter, - Del => Key::Backspace, + DpadUp => Key::Action(Action::ArrowUp), + DpadDown => Key::Action(Action::ArrowDown), + DpadLeft => Key::Action(Action::ArrowLeft), + DpadRight => Key::Action(Action::ArrowRight), + DpadCenter => Key::Action(Action::Enter), + + VolumeUp => Key::Action(Action::AudioVolumeUp), + VolumeDown => Key::Action(Action::AudioVolumeDown), + Power => Key::Action(Action::Power), + Camera => Key::Action(Action::Camera), + Clear => Key::Action(Action::Clear), + + AltLeft => Key::Action(Action::Alt), + AltRight => Key::Action(Action::Alt), + ShiftLeft => Key::Action(Action::Shift), + ShiftRight => Key::Action(Action::Shift), + Tab => Key::Action(Action::Tab), + Space => Key::Action(Action::Space), + Sym => Key::Action(Action::Symbol), + Explorer => Key::Action(Action::LaunchWebBrowser), + Envelope => Key::Action(Action::LaunchMail), + Enter => Key::Action(Action::Enter), + Del => Key::Action(Action::Backspace), // According to https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_NUM - Num => Key::Alt, - - Headsethook => Key::HeadsetHook, - Focus => Key::CameraFocus, - - Notification => Key::Notification, - Search => Key::BrowserSearch, - MediaPlayPause => Key::MediaPlayPause, - MediaStop => Key::MediaStop, - MediaNext => Key::MediaTrackNext, - MediaPrevious => Key::MediaTrackPrevious, - MediaRewind => Key::MediaRewind, - MediaFastForward => Key::MediaFastForward, - Mute => Key::MicrophoneVolumeMute, - PageUp => Key::PageUp, - PageDown => Key::PageDown, - - Escape => Key::Escape, - ForwardDel => Key::Delete, - CtrlLeft => Key::Control, - CtrlRight => Key::Control, - CapsLock => Key::CapsLock, - ScrollLock => Key::ScrollLock, - MetaLeft => Key::Super, - MetaRight => Key::Super, - Function => Key::Fn, - Sysrq => Key::PrintScreen, - Break => Key::Pause, - MoveHome => Key::Home, - MoveEnd => Key::End, - Insert => Key::Insert, - Forward => Key::BrowserForward, - MediaPlay => Key::MediaPlay, - MediaPause => Key::MediaPause, - MediaClose => Key::MediaClose, - MediaEject => Key::Eject, - MediaRecord => Key::MediaRecord, - F1 => Key::F1, - F2 => Key::F2, - F3 => Key::F3, - F4 => Key::F4, - F5 => Key::F5, - F6 => Key::F6, - F7 => Key::F7, - F8 => Key::F8, - F9 => Key::F9, - F10 => Key::F10, - F11 => Key::F11, - F12 => Key::F12, - NumLock => Key::NumLock, + Num => Key::Action(Action::Alt), + + Headsethook => Key::Action(Action::HeadsetHook), + Focus => Key::Action(Action::CameraFocus), + + Notification => Key::Action(Action::Notification), + Search => Key::Action(Action::BrowserSearch), + MediaPlayPause => Key::Action(Action::MediaPlayPause), + MediaStop => Key::Action(Action::MediaStop), + MediaNext => Key::Action(Action::MediaTrackNext), + MediaPrevious => Key::Action(Action::MediaTrackPrevious), + MediaRewind => Key::Action(Action::MediaRewind), + MediaFastForward => Key::Action(Action::MediaFastForward), + Mute => Key::Action(Action::MicrophoneVolumeMute), + PageUp => Key::Action(Action::PageUp), + PageDown => Key::Action(Action::PageDown), + + Escape => Key::Action(Action::Escape), + ForwardDel => Key::Action(Action::Delete), + CtrlLeft => Key::Action(Action::Control), + CtrlRight => Key::Action(Action::Control), + CapsLock => Key::Action(Action::CapsLock), + ScrollLock => Key::Action(Action::ScrollLock), + MetaLeft => Key::Action(Action::Super), + MetaRight => Key::Action(Action::Super), + Function => Key::Action(Action::Fn), + Sysrq => Key::Action(Action::PrintScreen), + Break => Key::Action(Action::Pause), + MoveHome => Key::Action(Action::Home), + MoveEnd => Key::Action(Action::End), + Insert => Key::Action(Action::Insert), + Forward => Key::Action(Action::BrowserForward), + MediaPlay => Key::Action(Action::MediaPlay), + MediaPause => Key::Action(Action::MediaPause), + MediaClose => Key::Action(Action::MediaClose), + MediaEject => Key::Action(Action::Eject), + MediaRecord => Key::Action(Action::MediaRecord), + F1 => Key::Action(Action::F1), + F2 => Key::Action(Action::F2), + F3 => Key::Action(Action::F3), + F4 => Key::Action(Action::F4), + F5 => Key::Action(Action::F5), + F6 => Key::Action(Action::F6), + F7 => Key::Action(Action::F7), + F8 => Key::Action(Action::F8), + F9 => Key::Action(Action::F9), + F10 => Key::Action(Action::F10), + F11 => Key::Action(Action::F11), + F12 => Key::Action(Action::F12), + NumLock => Key::Action(Action::NumLock), Numpad0 => Key::Character("0".into()), Numpad1 => Key::Character("1".into()), Numpad2 => Key::Character("2".into()), @@ -382,97 +382,97 @@ pub fn to_logical(key_char: Option, keycode: Keycode) -> Key { NumpadAdd => Key::Character("+".into()), NumpadDot => Key::Character(".".into()), NumpadComma => Key::Character(",".into()), - NumpadEnter => Key::Enter, + NumpadEnter => Key::Action(Action::Enter), NumpadEquals => Key::Character("=".into()), NumpadLeftParen => Key::Character("(".into()), NumpadRightParen => Key::Character(")".into()), - VolumeMute => Key::AudioVolumeMute, - Info => Key::Info, - ChannelUp => Key::ChannelUp, - ChannelDown => Key::ChannelDown, - ZoomIn => Key::ZoomIn, - ZoomOut => Key::ZoomOut, - Tv => Key::TV, - Guide => Key::Guide, - Dvr => Key::DVR, - Bookmark => Key::BrowserFavorites, - Captions => Key::ClosedCaptionToggle, - Settings => Key::Settings, - TvPower => Key::TVPower, - TvInput => Key::TVInput, - StbPower => Key::STBPower, - StbInput => Key::STBInput, - AvrPower => Key::AVRPower, - AvrInput => Key::AVRInput, - ProgRed => Key::ColorF0Red, - ProgGreen => Key::ColorF1Green, - ProgYellow => Key::ColorF2Yellow, - ProgBlue => Key::ColorF3Blue, - AppSwitch => Key::AppSwitch, - LanguageSwitch => Key::GroupNext, - MannerMode => Key::MannerMode, - Keycode3dMode => Key::TV3DMode, - Contacts => Key::LaunchContacts, - Calendar => Key::LaunchCalendar, - Music => Key::LaunchMusicPlayer, - Calculator => Key::LaunchApplication2, - ZenkakuHankaku => Key::ZenkakuHankaku, - Eisu => Key::Eisu, - Muhenkan => Key::NonConvert, - Henkan => Key::Convert, - KatakanaHiragana => Key::HiraganaKatakana, - Kana => Key::KanjiMode, - BrightnessDown => Key::BrightnessDown, - BrightnessUp => Key::BrightnessUp, - MediaAudioTrack => Key::MediaAudioTrack, - Sleep => Key::Standby, - Wakeup => Key::WakeUp, - Pairing => Key::Pairing, - MediaTopMenu => Key::MediaTopMenu, - LastChannel => Key::MediaLast, - TvDataService => Key::TVDataService, - VoiceAssist => Key::VoiceDial, - TvRadioService => Key::TVRadioService, - TvTeletext => Key::Teletext, - TvNumberEntry => Key::TVNumberEntry, - TvTerrestrialAnalog => Key::TVTerrestrialAnalog, - TvTerrestrialDigital => Key::TVTerrestrialDigital, - TvSatellite => Key::TVSatellite, - TvSatelliteBs => Key::TVSatelliteBS, - TvSatelliteCs => Key::TVSatelliteCS, - TvSatelliteService => Key::TVSatelliteToggle, - TvNetwork => Key::TVNetwork, - TvAntennaCable => Key::TVAntennaCable, - TvInputHdmi1 => Key::TVInputHDMI1, - TvInputHdmi2 => Key::TVInputHDMI2, - TvInputHdmi3 => Key::TVInputHDMI3, - TvInputHdmi4 => Key::TVInputHDMI4, - TvInputComposite1 => Key::TVInputComposite1, - TvInputComposite2 => Key::TVInputComposite2, - TvInputComponent1 => Key::TVInputComponent1, - TvInputComponent2 => Key::TVInputComponent2, - TvInputVga1 => Key::TVInputVGA1, - TvAudioDescription => Key::TVAudioDescription, - TvAudioDescriptionMixUp => Key::TVAudioDescriptionMixUp, - TvAudioDescriptionMixDown => Key::TVAudioDescriptionMixDown, - TvZoomMode => Key::ZoomToggle, - TvContentsMenu => Key::TVContentsMenu, - TvMediaContextMenu => Key::TVMediaContext, - TvTimerProgramming => Key::TVTimer, - Help => Key::Help, - NavigatePrevious => Key::NavigatePrevious, - NavigateNext => Key::NavigateNext, - NavigateIn => Key::NavigateIn, - NavigateOut => Key::NavigateOut, - MediaSkipForward => Key::MediaSkipForward, - MediaSkipBackward => Key::MediaSkipBackward, - MediaStepForward => Key::MediaStepForward, - MediaStepBackward => Key::MediaStepBackward, - Cut => Key::Cut, - Copy => Key::Copy, - Paste => Key::Paste, - Refresh => Key::BrowserRefresh, + VolumeMute => Key::Action(Action::AudioVolumeMute), + Info => Key::Action(Action::Info), + ChannelUp => Key::Action(Action::ChannelUp), + ChannelDown => Key::Action(Action::ChannelDown), + ZoomIn => Key::Action(Action::ZoomIn), + ZoomOut => Key::Action(Action::ZoomOut), + Tv => Key::Action(Action::TV), + Guide => Key::Action(Action::Guide), + Dvr => Key::Action(Action::DVR), + Bookmark => Key::Action(Action::BrowserFavorites), + Captions => Key::Action(Action::ClosedCaptionToggle), + Settings => Key::Action(Action::Settings), + TvPower => Key::Action(Action::TVPower), + TvInput => Key::Action(Action::TVInput), + StbPower => Key::Action(Action::STBPower), + StbInput => Key::Action(Action::STBInput), + AvrPower => Key::Action(Action::AVRPower), + AvrInput => Key::Action(Action::AVRInput), + ProgRed => Key::Action(Action::ColorF0Red), + ProgGreen => Key::Action(Action::ColorF1Green), + ProgYellow => Key::Action(Action::ColorF2Yellow), + ProgBlue => Key::Action(Action::ColorF3Blue), + AppSwitch => Key::Action(Action::AppSwitch), + LanguageSwitch => Key::Action(Action::GroupNext), + MannerMode => Key::Action(Action::MannerMode), + Keycode3dMode => Key::Action(Action::TV3DMode), + Contacts => Key::Action(Action::LaunchContacts), + Calendar => Key::Action(Action::LaunchCalendar), + Music => Key::Action(Action::LaunchMusicPlayer), + Calculator => Key::Action(Action::LaunchApplication2), + ZenkakuHankaku => Key::Action(Action::ZenkakuHankaku), + Eisu => Key::Action(Action::Eisu), + Muhenkan => Key::Action(Action::NonConvert), + Henkan => Key::Action(Action::Convert), + KatakanaHiragana => Key::Action(Action::HiraganaKatakana), + Kana => Key::Action(Action::KanjiMode), + BrightnessDown => Key::Action(Action::BrightnessDown), + BrightnessUp => Key::Action(Action::BrightnessUp), + MediaAudioTrack => Key::Action(Action::MediaAudioTrack), + Sleep => Key::Action(Action::Standby), + Wakeup => Key::Action(Action::WakeUp), + Pairing => Key::Action(Action::Pairing), + MediaTopMenu => Key::Action(Action::MediaTopMenu), + LastChannel => Key::Action(Action::MediaLast), + TvDataService => Key::Action(Action::TVDataService), + VoiceAssist => Key::Action(Action::VoiceDial), + TvRadioService => Key::Action(Action::TVRadioService), + TvTeletext => Key::Action(Action::Teletext), + TvNumberEntry => Key::Action(Action::TVNumberEntry), + TvTerrestrialAnalog => Key::Action(Action::TVTerrestrialAnalog), + TvTerrestrialDigital => Key::Action(Action::TVTerrestrialDigital), + TvSatellite => Key::Action(Action::TVSatellite), + TvSatelliteBs => Key::Action(Action::TVSatelliteBS), + TvSatelliteCs => Key::Action(Action::TVSatelliteCS), + TvSatelliteService => Key::Action(Action::TVSatelliteToggle), + TvNetwork => Key::Action(Action::TVNetwork), + TvAntennaCable => Key::Action(Action::TVAntennaCable), + TvInputHdmi1 => Key::Action(Action::TVInputHDMI1), + TvInputHdmi2 => Key::Action(Action::TVInputHDMI2), + TvInputHdmi3 => Key::Action(Action::TVInputHDMI3), + TvInputHdmi4 => Key::Action(Action::TVInputHDMI4), + TvInputComposite1 => Key::Action(Action::TVInputComposite1), + TvInputComposite2 => Key::Action(Action::TVInputComposite2), + TvInputComponent1 => Key::Action(Action::TVInputComponent1), + TvInputComponent2 => Key::Action(Action::TVInputComponent2), + TvInputVga1 => Key::Action(Action::TVInputVGA1), + TvAudioDescription => Key::Action(Action::TVAudioDescription), + TvAudioDescriptionMixUp => Key::Action(Action::TVAudioDescriptionMixUp), + TvAudioDescriptionMixDown => Key::Action(Action::TVAudioDescriptionMixDown), + TvZoomMode => Key::Action(Action::ZoomToggle), + TvContentsMenu => Key::Action(Action::TVContentsMenu), + TvMediaContextMenu => Key::Action(Action::TVMediaContext), + TvTimerProgramming => Key::Action(Action::TVTimer), + Help => Key::Action(Action::Help), + NavigatePrevious => Key::Action(Action::NavigatePrevious), + NavigateNext => Key::Action(Action::NavigateNext), + NavigateIn => Key::Action(Action::NavigateIn), + NavigateOut => Key::Action(Action::NavigateOut), + MediaSkipForward => Key::Action(Action::MediaSkipForward), + MediaSkipBackward => Key::Action(Action::MediaSkipBackward), + MediaStepForward => Key::Action(Action::MediaStepForward), + MediaStepBackward => Key::Action(Action::MediaStepBackward), + Cut => Key::Action(Action::Cut), + Copy => Key::Action(Action::Copy), + Paste => Key::Action(Action::Paste), + Refresh => Key::Action(Action::BrowserRefresh), // ----------------------------------------------------------------- // Keycodes that don't have a logical Key mapping diff --git a/src/platform_impl/linux/common/keymap.rs b/src/platform_impl/linux/common/keymap.rs index a7b35d55da..fb0ceee4d2 100644 --- a/src/platform_impl/linux/common/keymap.rs +++ b/src/platform_impl/linux/common/keymap.rs @@ -1,6 +1,6 @@ //! Convert XKB keys to Winit keys. -use crate::keyboard::{Key, KeyCode, KeyLocation, NativeKey, NativeKeyCode, PhysicalKey}; +use crate::keyboard::{Action, Key, KeyCode, KeyLocation, NativeKey, NativeKeyCode, PhysicalKey}; /// Map the raw X11-style keycode to the `KeyCode` enum. /// @@ -424,213 +424,213 @@ pub fn physicalkey_to_scancode(key: PhysicalKey) -> Option { pub fn keysym_to_key(keysym: u32) -> Key { use xkbcommon_dl::keysyms; - match keysym { + Key::Action(match keysym { // TTY function keys - keysyms::BackSpace => Key::Backspace, - keysyms::Tab => Key::Tab, - // keysyms::Linefeed => Key::Linefeed, - keysyms::Clear => Key::Clear, - keysyms::Return => Key::Enter, - keysyms::Pause => Key::Pause, - keysyms::Scroll_Lock => Key::ScrollLock, - keysyms::Sys_Req => Key::PrintScreen, - keysyms::Escape => Key::Escape, - keysyms::Delete => Key::Delete, + keysyms::BackSpace => Action::Backspace, + keysyms::Tab => Action::Tab, + // keysyms::Linefeed => Action::Linefeed, + keysyms::Clear => Action::Clear, + keysyms::Return => Action::Enter, + keysyms::Pause => Action::Pause, + keysyms::Scroll_Lock => Action::ScrollLock, + keysyms::Sys_Req => Action::PrintScreen, + keysyms::Escape => Action::Escape, + keysyms::Delete => Action::Delete, // IME keys - keysyms::Multi_key => Key::Compose, - keysyms::Codeinput => Key::CodeInput, - keysyms::SingleCandidate => Key::SingleCandidate, - keysyms::MultipleCandidate => Key::AllCandidates, - keysyms::PreviousCandidate => Key::PreviousCandidate, + keysyms::Multi_key => Action::Compose, + keysyms::Codeinput => Action::CodeInput, + keysyms::SingleCandidate => Action::SingleCandidate, + keysyms::MultipleCandidate => Action::AllCandidates, + keysyms::PreviousCandidate => Action::PreviousCandidate, // Japanese keys - keysyms::Kanji => Key::KanjiMode, - keysyms::Muhenkan => Key::NonConvert, - keysyms::Henkan_Mode => Key::Convert, - keysyms::Romaji => Key::Romaji, - keysyms::Hiragana => Key::Hiragana, - keysyms::Hiragana_Katakana => Key::HiraganaKatakana, - keysyms::Zenkaku => Key::Zenkaku, - keysyms::Hankaku => Key::Hankaku, - keysyms::Zenkaku_Hankaku => Key::ZenkakuHankaku, - // keysyms::Touroku => Key::Touroku, - // keysyms::Massyo => Key::Massyo, - keysyms::Kana_Lock => Key::KanaMode, - keysyms::Kana_Shift => Key::KanaMode, - keysyms::Eisu_Shift => Key::Alphanumeric, - keysyms::Eisu_toggle => Key::Alphanumeric, + keysyms::Kanji => Action::KanjiMode, + keysyms::Muhenkan => Action::NonConvert, + keysyms::Henkan_Mode => Action::Convert, + keysyms::Romaji => Action::Romaji, + keysyms::Hiragana => Action::Hiragana, + keysyms::Hiragana_Katakana => Action::HiraganaKatakana, + keysyms::Zenkaku => Action::Zenkaku, + keysyms::Hankaku => Action::Hankaku, + keysyms::Zenkaku_Hankaku => Action::ZenkakuHankaku, + // keysyms::Touroku => Action::Touroku, + // keysyms::Massyo => Action::Massyo, + keysyms::Kana_Lock => Action::KanaMode, + keysyms::Kana_Shift => Action::KanaMode, + keysyms::Eisu_Shift => Action::Alphanumeric, + keysyms::Eisu_toggle => Action::Alphanumeric, // NOTE: The next three items are aliases for values we've already mapped. - // keysyms::Kanji_Bangou => Key::CodeInput, - // keysyms::Zen_Koho => Key::AllCandidates, - // keysyms::Mae_Koho => Key::PreviousCandidate, + // keysyms::Kanji_Bangou => Action::CodeInput, + // keysyms::Zen_Koho => Action::AllCandidates, + // keysyms::Mae_Koho => Action::PreviousCandidate, // Cursor control & motion - keysyms::Home => Key::Home, - keysyms::Left => Key::ArrowLeft, - keysyms::Up => Key::ArrowUp, - keysyms::Right => Key::ArrowRight, - keysyms::Down => Key::ArrowDown, - // keysyms::Prior => Key::PageUp, - keysyms::Page_Up => Key::PageUp, - // keysyms::Next => Key::PageDown, - keysyms::Page_Down => Key::PageDown, - keysyms::End => Key::End, - // keysyms::Begin => Key::Begin, + keysyms::Home => Action::Home, + keysyms::Left => Action::ArrowLeft, + keysyms::Up => Action::ArrowUp, + keysyms::Right => Action::ArrowRight, + keysyms::Down => Action::ArrowDown, + // keysyms::Prior => Action::PageUp, + keysyms::Page_Up => Action::PageUp, + // keysyms::Next => Action::PageDown, + keysyms::Page_Down => Action::PageDown, + keysyms::End => Action::End, + // keysyms::Begin => Action::Begin, // Misc. functions - keysyms::Select => Key::Select, - keysyms::Print => Key::PrintScreen, - keysyms::Execute => Key::Execute, - keysyms::Insert => Key::Insert, - keysyms::Undo => Key::Undo, - keysyms::Redo => Key::Redo, - keysyms::Menu => Key::ContextMenu, - keysyms::Find => Key::Find, - keysyms::Cancel => Key::Cancel, - keysyms::Help => Key::Help, - keysyms::Break => Key::Pause, - keysyms::Mode_switch => Key::ModeChange, - // keysyms::script_switch => Key::ModeChange, - keysyms::Num_Lock => Key::NumLock, + keysyms::Select => Action::Select, + keysyms::Print => Action::PrintScreen, + keysyms::Execute => Action::Execute, + keysyms::Insert => Action::Insert, + keysyms::Undo => Action::Undo, + keysyms::Redo => Action::Redo, + keysyms::Menu => Action::ContextMenu, + keysyms::Find => Action::Find, + keysyms::Cancel => Action::Cancel, + keysyms::Help => Action::Help, + keysyms::Break => Action::Pause, + keysyms::Mode_switch => Action::ModeChange, + // keysyms::script_switch => Action::ModeChange, + keysyms::Num_Lock => Action::NumLock, // Keypad keys - // keysyms::KP_Space => Key::Character(" "), - keysyms::KP_Tab => Key::Tab, - keysyms::KP_Enter => Key::Enter, - keysyms::KP_F1 => Key::F1, - keysyms::KP_F2 => Key::F2, - keysyms::KP_F3 => Key::F3, - keysyms::KP_F4 => Key::F4, - keysyms::KP_Home => Key::Home, - keysyms::KP_Left => Key::ArrowLeft, - keysyms::KP_Up => Key::ArrowLeft, - keysyms::KP_Right => Key::ArrowRight, - keysyms::KP_Down => Key::ArrowDown, - // keysyms::KP_Prior => Key::PageUp, - keysyms::KP_Page_Up => Key::PageUp, - // keysyms::KP_Next => Key::PageDown, - keysyms::KP_Page_Down => Key::PageDown, - keysyms::KP_End => Key::End, + // keysyms::KP_Space => return Key::Character(" "), + keysyms::KP_Tab => Action::Tab, + keysyms::KP_Enter => Action::Enter, + keysyms::KP_F1 => Action::F1, + keysyms::KP_F2 => Action::F2, + keysyms::KP_F3 => Action::F3, + keysyms::KP_F4 => Action::F4, + keysyms::KP_Home => Action::Home, + keysyms::KP_Left => Action::ArrowLeft, + keysyms::KP_Up => Action::ArrowLeft, + keysyms::KP_Right => Action::ArrowRight, + keysyms::KP_Down => Action::ArrowDown, + // keysyms::KP_Prior => Action::PageUp, + keysyms::KP_Page_Up => Action::PageUp, + // keysyms::KP_Next => Action::PageDown, + keysyms::KP_Page_Down => Action::PageDown, + keysyms::KP_End => Action::End, // This is the key labeled "5" on the numpad when NumLock is off. - // keysyms::KP_Begin => Key::Begin, - keysyms::KP_Insert => Key::Insert, - keysyms::KP_Delete => Key::Delete, - // keysyms::KP_Equal => Key::Equal, - // keysyms::KP_Multiply => Key::Multiply, - // keysyms::KP_Add => Key::Add, - // keysyms::KP_Separator => Key::Separator, - // keysyms::KP_Subtract => Key::Subtract, - // keysyms::KP_Decimal => Key::Decimal, - // keysyms::KP_Divide => Key::Divide, - - // keysyms::KP_0 => Key::Character("0"), - // keysyms::KP_1 => Key::Character("1"), - // keysyms::KP_2 => Key::Character("2"), - // keysyms::KP_3 => Key::Character("3"), - // keysyms::KP_4 => Key::Character("4"), - // keysyms::KP_5 => Key::Character("5"), - // keysyms::KP_6 => Key::Character("6"), - // keysyms::KP_7 => Key::Character("7"), - // keysyms::KP_8 => Key::Character("8"), - // keysyms::KP_9 => Key::Character("9"), + // keysyms::KP_Begin => Action::Begin, + keysyms::KP_Insert => Action::Insert, + keysyms::KP_Delete => Action::Delete, + // keysyms::KP_Equal => Action::Equal, + // keysyms::KP_Multiply => Action::Multiply, + // keysyms::KP_Add => Action::Add, + // keysyms::KP_Separator => Action::Separator, + // keysyms::KP_Subtract => Action::Subtract, + // keysyms::KP_Decimal => Action::Decimal, + // keysyms::KP_Divide => Action::Divide, + + // keysyms::KP_0 => return Key::Character("0"), + // keysyms::KP_1 => return Key::Character("1"), + // keysyms::KP_2 => return Key::Character("2"), + // keysyms::KP_3 => return Key::Character("3"), + // keysyms::KP_4 => return Key::Character("4"), + // keysyms::KP_5 => return Key::Character("5"), + // keysyms::KP_6 => return Key::Character("6"), + // keysyms::KP_7 => return Key::Character("7"), + // keysyms::KP_8 => return Key::Character("8"), + // keysyms::KP_9 => return Key::Character("9"), // Function keys - keysyms::F1 => Key::F1, - keysyms::F2 => Key::F2, - keysyms::F3 => Key::F3, - keysyms::F4 => Key::F4, - keysyms::F5 => Key::F5, - keysyms::F6 => Key::F6, - keysyms::F7 => Key::F7, - keysyms::F8 => Key::F8, - keysyms::F9 => Key::F9, - keysyms::F10 => Key::F10, - keysyms::F11 => Key::F11, - keysyms::F12 => Key::F12, - keysyms::F13 => Key::F13, - keysyms::F14 => Key::F14, - keysyms::F15 => Key::F15, - keysyms::F16 => Key::F16, - keysyms::F17 => Key::F17, - keysyms::F18 => Key::F18, - keysyms::F19 => Key::F19, - keysyms::F20 => Key::F20, - keysyms::F21 => Key::F21, - keysyms::F22 => Key::F22, - keysyms::F23 => Key::F23, - keysyms::F24 => Key::F24, - keysyms::F25 => Key::F25, - keysyms::F26 => Key::F26, - keysyms::F27 => Key::F27, - keysyms::F28 => Key::F28, - keysyms::F29 => Key::F29, - keysyms::F30 => Key::F30, - keysyms::F31 => Key::F31, - keysyms::F32 => Key::F32, - keysyms::F33 => Key::F33, - keysyms::F34 => Key::F34, - keysyms::F35 => Key::F35, + keysyms::F1 => Action::F1, + keysyms::F2 => Action::F2, + keysyms::F3 => Action::F3, + keysyms::F4 => Action::F4, + keysyms::F5 => Action::F5, + keysyms::F6 => Action::F6, + keysyms::F7 => Action::F7, + keysyms::F8 => Action::F8, + keysyms::F9 => Action::F9, + keysyms::F10 => Action::F10, + keysyms::F11 => Action::F11, + keysyms::F12 => Action::F12, + keysyms::F13 => Action::F13, + keysyms::F14 => Action::F14, + keysyms::F15 => Action::F15, + keysyms::F16 => Action::F16, + keysyms::F17 => Action::F17, + keysyms::F18 => Action::F18, + keysyms::F19 => Action::F19, + keysyms::F20 => Action::F20, + keysyms::F21 => Action::F21, + keysyms::F22 => Action::F22, + keysyms::F23 => Action::F23, + keysyms::F24 => Action::F24, + keysyms::F25 => Action::F25, + keysyms::F26 => Action::F26, + keysyms::F27 => Action::F27, + keysyms::F28 => Action::F28, + keysyms::F29 => Action::F29, + keysyms::F30 => Action::F30, + keysyms::F31 => Action::F31, + keysyms::F32 => Action::F32, + keysyms::F33 => Action::F33, + keysyms::F34 => Action::F34, + keysyms::F35 => Action::F35, // Modifiers - keysyms::Shift_L => Key::Shift, - keysyms::Shift_R => Key::Shift, - keysyms::Control_L => Key::Control, - keysyms::Control_R => Key::Control, - keysyms::Caps_Lock => Key::CapsLock, - // keysyms::Shift_Lock => Key::ShiftLock, - - // keysyms::Meta_L => Key::Meta, - // keysyms::Meta_R => Key::Meta, - keysyms::Alt_L => Key::Alt, - keysyms::Alt_R => Key::Alt, - keysyms::Super_L => Key::Super, - keysyms::Super_R => Key::Super, - keysyms::Hyper_L => Key::Hyper, - keysyms::Hyper_R => Key::Hyper, + keysyms::Shift_L => Action::Shift, + keysyms::Shift_R => Action::Shift, + keysyms::Control_L => Action::Control, + keysyms::Control_R => Action::Control, + keysyms::Caps_Lock => Action::CapsLock, + // keysyms::Shift_Lock => Action::ShiftLock, + + // keysyms::Meta_L => Action::Meta, + // keysyms::Meta_R => Action::Meta, + keysyms::Alt_L => Action::Alt, + keysyms::Alt_R => Action::Alt, + keysyms::Super_L => Action::Super, + keysyms::Super_R => Action::Super, + keysyms::Hyper_L => Action::Hyper, + keysyms::Hyper_R => Action::Hyper, // XKB function and modifier keys - // keysyms::ISO_Lock => Key::IsoLock, - // keysyms::ISO_Level2_Latch => Key::IsoLevel2Latch, - keysyms::ISO_Level3_Shift => Key::AltGraph, - keysyms::ISO_Level3_Latch => Key::AltGraph, - keysyms::ISO_Level3_Lock => Key::AltGraph, - // keysyms::ISO_Level5_Shift => Key::IsoLevel5Shift, - // keysyms::ISO_Level5_Latch => Key::IsoLevel5Latch, - // keysyms::ISO_Level5_Lock => Key::IsoLevel5Lock, - // keysyms::ISO_Group_Shift => Key::IsoGroupShift, - // keysyms::ISO_Group_Latch => Key::IsoGroupLatch, - // keysyms::ISO_Group_Lock => Key::IsoGroupLock, - keysyms::ISO_Next_Group => Key::GroupNext, - // keysyms::ISO_Next_Group_Lock => Key::GroupNextLock, - keysyms::ISO_Prev_Group => Key::GroupPrevious, - // keysyms::ISO_Prev_Group_Lock => Key::GroupPreviousLock, - keysyms::ISO_First_Group => Key::GroupFirst, - // keysyms::ISO_First_Group_Lock => Key::GroupFirstLock, - keysyms::ISO_Last_Group => Key::GroupLast, - // keysyms::ISO_Last_Group_Lock => Key::GroupLastLock, + // keysyms::ISO_Lock => Action::IsoLock, + // keysyms::ISO_Level2_Latch => Action::IsoLevel2Latch, + keysyms::ISO_Level3_Shift => Action::AltGraph, + keysyms::ISO_Level3_Latch => Action::AltGraph, + keysyms::ISO_Level3_Lock => Action::AltGraph, + // keysyms::ISO_Level5_Shift => Action::IsoLevel5Shift, + // keysyms::ISO_Level5_Latch => Action::IsoLevel5Latch, + // keysyms::ISO_Level5_Lock => Action::IsoLevel5Lock, + // keysyms::ISO_Group_Shift => Action::IsoGroupShift, + // keysyms::ISO_Group_Latch => Action::IsoGroupLatch, + // keysyms::ISO_Group_Lock => Action::IsoGroupLock, + keysyms::ISO_Next_Group => Action::GroupNext, + // keysyms::ISO_Next_Group_Lock => Action::GroupNextLock, + keysyms::ISO_Prev_Group => Action::GroupPrevious, + // keysyms::ISO_Prev_Group_Lock => Action::GroupPreviousLock, + keysyms::ISO_First_Group => Action::GroupFirst, + // keysyms::ISO_First_Group_Lock => Action::GroupFirstLock, + keysyms::ISO_Last_Group => Action::GroupLast, + // keysyms::ISO_Last_Group_Lock => Action::GroupLastLock, // - keysyms::ISO_Left_Tab => Key::Tab, - // keysyms::ISO_Move_Line_Up => Key::IsoMoveLineUp, - // keysyms::ISO_Move_Line_Down => Key::IsoMoveLineDown, - // keysyms::ISO_Partial_Line_Up => Key::IsoPartialLineUp, - // keysyms::ISO_Partial_Line_Down => Key::IsoPartialLineDown, - // keysyms::ISO_Partial_Space_Left => Key::IsoPartialSpaceLeft, - // keysyms::ISO_Partial_Space_Right => Key::IsoPartialSpaceRight, - // keysyms::ISO_Set_Margin_Left => Key::IsoSetMarginLeft, - // keysyms::ISO_Set_Margin_Right => Key::IsoSetMarginRight, - // keysyms::ISO_Release_Margin_Left => Key::IsoReleaseMarginLeft, - // keysyms::ISO_Release_Margin_Right => Key::IsoReleaseMarginRight, - // keysyms::ISO_Release_Both_Margins => Key::IsoReleaseBothMargins, - // keysyms::ISO_Fast_Cursor_Left => Key::IsoFastCursorLeft, - // keysyms::ISO_Fast_Cursor_Right => Key::IsoFastCursorRight, - // keysyms::ISO_Fast_Cursor_Up => Key::IsoFastCursorUp, - // keysyms::ISO_Fast_Cursor_Down => Key::IsoFastCursorDown, - // keysyms::ISO_Continuous_Underline => Key::IsoContinuousUnderline, - // keysyms::ISO_Discontinuous_Underline => Key::IsoDiscontinuousUnderline, - // keysyms::ISO_Emphasize => Key::IsoEmphasize, - // keysyms::ISO_Center_Object => Key::IsoCenterObject, - keysyms::ISO_Enter => Key::Enter, + keysyms::ISO_Left_Tab => Action::Tab, + // keysyms::ISO_Move_Line_Up => Action::IsoMoveLineUp, + // keysyms::ISO_Move_Line_Down => Action::IsoMoveLineDown, + // keysyms::ISO_Partial_Line_Up => Action::IsoPartialLineUp, + // keysyms::ISO_Partial_Line_Down => Action::IsoPartialLineDown, + // keysyms::ISO_Partial_Space_Left => Action::IsoPartialSpaceLeft, + // keysyms::ISO_Partial_Space_Right => Action::IsoPartialSpaceRight, + // keysyms::ISO_Set_Margin_Left => Action::IsoSetMarginLeft, + // keysyms::ISO_Set_Margin_Right => Action::IsoSetMarginRight, + // keysyms::ISO_Release_Margin_Left => Action::IsoReleaseMarginLeft, + // keysyms::ISO_Release_Margin_Right => Action::IsoReleaseMarginRight, + // keysyms::ISO_Release_Both_Margins => Action::IsoReleaseBothMargins, + // keysyms::ISO_Fast_Cursor_Left => Action::IsoFastCursorLeft, + // keysyms::ISO_Fast_Cursor_Right => Action::IsoFastCursorRight, + // keysyms::ISO_Fast_Cursor_Up => Action::IsoFastCursorUp, + // keysyms::ISO_Fast_Cursor_Down => Action::IsoFastCursorDown, + // keysyms::ISO_Continuous_Underline => Action::IsoContinuousUnderline, + // keysyms::ISO_Discontinuous_Underline => Action::IsoDiscontinuousUnderline, + // keysyms::ISO_Emphasize => Action::IsoEmphasize, + // keysyms::ISO_Center_Object => Action::IsoCenterObject, + keysyms::ISO_Enter => Action::Enter, // dead_grave..dead_currency @@ -651,194 +651,194 @@ pub fn keysym_to_key(keysym: u32) -> Key { // ch..C_H // 3270 terminal keys - // keysyms::3270_Duplicate => Key::Duplicate, - // keysyms::3270_FieldMark => Key::FieldMark, - // keysyms::3270_Right2 => Key::Right2, - // keysyms::3270_Left2 => Key::Left2, - // keysyms::3270_BackTab => Key::BackTab, - keysyms::_3270_EraseEOF => Key::EraseEof, - // keysyms::3270_EraseInput => Key::EraseInput, - // keysyms::3270_Reset => Key::Reset, - // keysyms::3270_Quit => Key::Quit, - // keysyms::3270_PA1 => Key::Pa1, - // keysyms::3270_PA2 => Key::Pa2, - // keysyms::3270_PA3 => Key::Pa3, - // keysyms::3270_Test => Key::Test, - keysyms::_3270_Attn => Key::Attn, - // keysyms::3270_CursorBlink => Key::CursorBlink, - // keysyms::3270_AltCursor => Key::AltCursor, - // keysyms::3270_KeyClick => Key::KeyClick, - // keysyms::3270_Jump => Key::Jump, - // keysyms::3270_Ident => Key::Ident, - // keysyms::3270_Rule => Key::Rule, - // keysyms::3270_Copy => Key::Copy, - keysyms::_3270_Play => Key::Play, - // keysyms::3270_Setup => Key::Setup, - // keysyms::3270_Record => Key::Record, - // keysyms::3270_ChangeScreen => Key::ChangeScreen, - // keysyms::3270_DeleteWord => Key::DeleteWord, - keysyms::_3270_ExSelect => Key::ExSel, - keysyms::_3270_CursorSelect => Key::CrSel, - keysyms::_3270_PrintScreen => Key::PrintScreen, - keysyms::_3270_Enter => Key::Enter, - - keysyms::space => Key::Space, + // keysyms::3270_Duplicate => Action::Duplicate, + // keysyms::3270_FieldMark => Action::FieldMark, + // keysyms::3270_Right2 => Action::Right2, + // keysyms::3270_Left2 => Action::Left2, + // keysyms::3270_BackTab => Action::BackTab, + keysyms::_3270_EraseEOF => Action::EraseEof, + // keysyms::3270_EraseInput => Action::EraseInput, + // keysyms::3270_Reset => Action::Reset, + // keysyms::3270_Quit => Action::Quit, + // keysyms::3270_PA1 => Action::Pa1, + // keysyms::3270_PA2 => Action::Pa2, + // keysyms::3270_PA3 => Action::Pa3, + // keysyms::3270_Test => Action::Test, + keysyms::_3270_Attn => Action::Attn, + // keysyms::3270_CursorBlink => Action::CursorBlink, + // keysyms::3270_AltCursor => Action::AltCursor, + // keysyms::3270_KeyClick => Action::KeyClick, + // keysyms::3270_Jump => Action::Jump, + // keysyms::3270_Ident => Action::Ident, + // keysyms::3270_Rule => Action::Rule, + // keysyms::3270_Copy => Action::Copy, + keysyms::_3270_Play => Action::Play, + // keysyms::3270_Setup => Action::Setup, + // keysyms::3270_Record => Action::Record, + // keysyms::3270_ChangeScreen => Action::ChangeScreen, + // keysyms::3270_DeleteWord => Action::DeleteWord, + keysyms::_3270_ExSelect => Action::ExSel, + keysyms::_3270_CursorSelect => Action::CrSel, + keysyms::_3270_PrintScreen => Action::PrintScreen, + keysyms::_3270_Enter => Action::Enter, + + keysyms::space => Action::Space, // exclam..Sinh_kunddaliya // XFree86 - // keysyms::XF86_ModeLock => Key::ModeLock, + // keysyms::XF86_ModeLock => Action::ModeLock, // XFree86 - Backlight controls - keysyms::XF86_MonBrightnessUp => Key::BrightnessUp, - keysyms::XF86_MonBrightnessDown => Key::BrightnessDown, - // keysyms::XF86_KbdLightOnOff => Key::LightOnOff, - // keysyms::XF86_KbdBrightnessUp => Key::KeyboardBrightnessUp, - // keysyms::XF86_KbdBrightnessDown => Key::KeyboardBrightnessDown, + keysyms::XF86_MonBrightnessUp => Action::BrightnessUp, + keysyms::XF86_MonBrightnessDown => Action::BrightnessDown, + // keysyms::XF86_KbdLightOnOff => Action::LightOnOff, + // keysyms::XF86_KbdBrightnessUp => Action::KeyboardBrightnessUp, + // keysyms::XF86_KbdBrightnessDown => Action::KeyboardBrightnessDown, // XFree86 - "Internet" - keysyms::XF86_Standby => Key::Standby, - keysyms::XF86_AudioLowerVolume => Key::AudioVolumeDown, - keysyms::XF86_AudioRaiseVolume => Key::AudioVolumeUp, - keysyms::XF86_AudioPlay => Key::MediaPlay, - keysyms::XF86_AudioStop => Key::MediaStop, - keysyms::XF86_AudioPrev => Key::MediaTrackPrevious, - keysyms::XF86_AudioNext => Key::MediaTrackNext, - keysyms::XF86_HomePage => Key::BrowserHome, - keysyms::XF86_Mail => Key::LaunchMail, - // keysyms::XF86_Start => Key::Start, - keysyms::XF86_Search => Key::BrowserSearch, - keysyms::XF86_AudioRecord => Key::MediaRecord, + keysyms::XF86_Standby => Action::Standby, + keysyms::XF86_AudioLowerVolume => Action::AudioVolumeDown, + keysyms::XF86_AudioRaiseVolume => Action::AudioVolumeUp, + keysyms::XF86_AudioPlay => Action::MediaPlay, + keysyms::XF86_AudioStop => Action::MediaStop, + keysyms::XF86_AudioPrev => Action::MediaTrackPrevious, + keysyms::XF86_AudioNext => Action::MediaTrackNext, + keysyms::XF86_HomePage => Action::BrowserHome, + keysyms::XF86_Mail => Action::LaunchMail, + // keysyms::XF86_Start => Action::Start, + keysyms::XF86_Search => Action::BrowserSearch, + keysyms::XF86_AudioRecord => Action::MediaRecord, // XFree86 - PDA - keysyms::XF86_Calculator => Key::LaunchApplication2, - // keysyms::XF86_Memo => Key::Memo, - // keysyms::XF86_ToDoList => Key::ToDoList, - keysyms::XF86_Calendar => Key::LaunchCalendar, - keysyms::XF86_PowerDown => Key::Power, - // keysyms::XF86_ContrastAdjust => Key::AdjustContrast, - // keysyms::XF86_RockerUp => Key::RockerUp, - // keysyms::XF86_RockerDown => Key::RockerDown, - // keysyms::XF86_RockerEnter => Key::RockerEnter, + keysyms::XF86_Calculator => Action::LaunchApplication2, + // keysyms::XF86_Memo => Action::Memo, + // keysyms::XF86_ToDoList => Action::ToDoList, + keysyms::XF86_Calendar => Action::LaunchCalendar, + keysyms::XF86_PowerDown => Action::Power, + // keysyms::XF86_ContrastAdjust => Action::AdjustContrast, + // keysyms::XF86_RockerUp => Action::RockerUp, + // keysyms::XF86_RockerDown => Action::RockerDown, + // keysyms::XF86_RockerEnter => Action::RockerEnter, // XFree86 - More "Internet" - keysyms::XF86_Back => Key::BrowserBack, - keysyms::XF86_Forward => Key::BrowserForward, - // keysyms::XF86_Stop => Key::Stop, - keysyms::XF86_Refresh => Key::BrowserRefresh, - keysyms::XF86_PowerOff => Key::Power, - keysyms::XF86_WakeUp => Key::WakeUp, - keysyms::XF86_Eject => Key::Eject, - keysyms::XF86_ScreenSaver => Key::LaunchScreenSaver, - keysyms::XF86_WWW => Key::LaunchWebBrowser, - keysyms::XF86_Sleep => Key::Standby, - keysyms::XF86_Favorites => Key::BrowserFavorites, - keysyms::XF86_AudioPause => Key::MediaPause, - // keysyms::XF86_AudioMedia => Key::AudioMedia, - keysyms::XF86_MyComputer => Key::LaunchApplication1, - // keysyms::XF86_VendorHome => Key::VendorHome, - // keysyms::XF86_LightBulb => Key::LightBulb, - // keysyms::XF86_Shop => Key::BrowserShop, - // keysyms::XF86_History => Key::BrowserHistory, - // keysyms::XF86_OpenURL => Key::OpenUrl, - // keysyms::XF86_AddFavorite => Key::AddFavorite, - // keysyms::XF86_HotLinks => Key::HotLinks, - // keysyms::XF86_BrightnessAdjust => Key::BrightnessAdjust, - // keysyms::XF86_Finance => Key::BrowserFinance, - // keysyms::XF86_Community => Key::BrowserCommunity, - keysyms::XF86_AudioRewind => Key::MediaRewind, + keysyms::XF86_Back => Action::BrowserBack, + keysyms::XF86_Forward => Action::BrowserForward, + // keysyms::XF86_Stop => Action::Stop, + keysyms::XF86_Refresh => Action::BrowserRefresh, + keysyms::XF86_PowerOff => Action::Power, + keysyms::XF86_WakeUp => Action::WakeUp, + keysyms::XF86_Eject => Action::Eject, + keysyms::XF86_ScreenSaver => Action::LaunchScreenSaver, + keysyms::XF86_WWW => Action::LaunchWebBrowser, + keysyms::XF86_Sleep => Action::Standby, + keysyms::XF86_Favorites => Action::BrowserFavorites, + keysyms::XF86_AudioPause => Action::MediaPause, + // keysyms::XF86_AudioMedia => Action::AudioMedia, + keysyms::XF86_MyComputer => Action::LaunchApplication1, + // keysyms::XF86_VendorHome => Action::VendorHome, + // keysyms::XF86_LightBulb => Action::LightBulb, + // keysyms::XF86_Shop => Action::BrowserShop, + // keysyms::XF86_History => Action::BrowserHistory, + // keysyms::XF86_OpenURL => Action::OpenUrl, + // keysyms::XF86_AddFavorite => Action::AddFavorite, + // keysyms::XF86_HotLinks => Action::HotLinks, + // keysyms::XF86_BrightnessAdjust => Action::BrightnessAdjust, + // keysyms::XF86_Finance => Action::BrowserFinance, + // keysyms::XF86_Community => Action::BrowserCommunity, + keysyms::XF86_AudioRewind => Action::MediaRewind, // keysyms::XF86_BackForward => Key::???, // XF86_Launch0..XF86_LaunchF // XF86_ApplicationLeft..XF86_CD - keysyms::XF86_Calculater => Key::LaunchApplication2, // Nice typo, libxkbcommon :) + keysyms::XF86_Calculater => Action::LaunchApplication2, // Nice typo, libxkbcommon :) // XF86_Clear - keysyms::XF86_Close => Key::Close, - keysyms::XF86_Copy => Key::Copy, - keysyms::XF86_Cut => Key::Cut, + keysyms::XF86_Close => Action::Close, + keysyms::XF86_Copy => Action::Copy, + keysyms::XF86_Cut => Action::Cut, // XF86_Display..XF86_Documents - keysyms::XF86_Excel => Key::LaunchSpreadsheet, + keysyms::XF86_Excel => Action::LaunchSpreadsheet, // XF86_Explorer..XF86iTouch - keysyms::XF86_LogOff => Key::LogOff, + keysyms::XF86_LogOff => Action::LogOff, // XF86_Market..XF86_MenuPB - keysyms::XF86_MySites => Key::BrowserFavorites, - keysyms::XF86_New => Key::New, + keysyms::XF86_MySites => Action::BrowserFavorites, + keysyms::XF86_New => Action::New, // XF86_News..XF86_OfficeHome - keysyms::XF86_Open => Key::Open, + keysyms::XF86_Open => Action::Open, // XF86_Option - keysyms::XF86_Paste => Key::Paste, - keysyms::XF86_Phone => Key::LaunchPhone, + keysyms::XF86_Paste => Action::Paste, + keysyms::XF86_Phone => Action::LaunchPhone, // XF86_Q - keysyms::XF86_Reply => Key::MailReply, - keysyms::XF86_Reload => Key::BrowserRefresh, + keysyms::XF86_Reply => Action::MailReply, + keysyms::XF86_Reload => Action::BrowserRefresh, // XF86_RotateWindows..XF86_RotationKB - keysyms::XF86_Save => Key::Save, + keysyms::XF86_Save => Action::Save, // XF86_ScrollUp..XF86_ScrollClick - keysyms::XF86_Send => Key::MailSend, - keysyms::XF86_Spell => Key::SpellCheck, - keysyms::XF86_SplitScreen => Key::SplitScreenToggle, + keysyms::XF86_Send => Action::MailSend, + keysyms::XF86_Spell => Action::SpellCheck, + keysyms::XF86_SplitScreen => Action::SplitScreenToggle, // XF86_Support..XF86_User2KB - keysyms::XF86_Video => Key::LaunchMediaPlayer, + keysyms::XF86_Video => Action::LaunchMediaPlayer, // XF86_WheelButton - keysyms::XF86_Word => Key::LaunchWordProcessor, + keysyms::XF86_Word => Action::LaunchWordProcessor, // XF86_Xfer - keysyms::XF86_ZoomIn => Key::ZoomIn, - keysyms::XF86_ZoomOut => Key::ZoomOut, + keysyms::XF86_ZoomIn => Action::ZoomIn, + keysyms::XF86_ZoomOut => Action::ZoomOut, // XF86_Away..XF86_Messenger - keysyms::XF86_WebCam => Key::LaunchWebCam, - keysyms::XF86_MailForward => Key::MailForward, + keysyms::XF86_WebCam => Action::LaunchWebCam, + keysyms::XF86_MailForward => Action::MailForward, // XF86_Pictures - keysyms::XF86_Music => Key::LaunchMusicPlayer, + keysyms::XF86_Music => Action::LaunchMusicPlayer, // XF86_Battery..XF86_UWB // - keysyms::XF86_AudioForward => Key::MediaFastForward, + keysyms::XF86_AudioForward => Action::MediaFastForward, // XF86_AudioRepeat - keysyms::XF86_AudioRandomPlay => Key::RandomToggle, - keysyms::XF86_Subtitle => Key::Subtitle, - keysyms::XF86_AudioCycleTrack => Key::MediaAudioTrack, + keysyms::XF86_AudioRandomPlay => Action::RandomToggle, + keysyms::XF86_Subtitle => Action::Subtitle, + keysyms::XF86_AudioCycleTrack => Action::MediaAudioTrack, // XF86_CycleAngle..XF86_Blue // - keysyms::XF86_Suspend => Key::Standby, - keysyms::XF86_Hibernate => Key::Hibernate, + keysyms::XF86_Suspend => Action::Standby, + keysyms::XF86_Hibernate => Action::Hibernate, // XF86_TouchpadToggle..XF86_TouchpadOff // - keysyms::XF86_AudioMute => Key::AudioVolumeMute, + keysyms::XF86_AudioMute => Action::AudioVolumeMute, // XF86_Switch_VT_1..XF86_Switch_VT_12 // XF86_Ungrab..XF86_ClearGrab - keysyms::XF86_Next_VMode => Key::VideoModeNext, - // keysyms::XF86_Prev_VMode => Key::VideoModePrevious, + keysyms::XF86_Next_VMode => Action::VideoModeNext, + // keysyms::XF86_Prev_VMode => Action::VideoModePrevious, // XF86_LogWindowTree..XF86_LogGrabInfo // SunFA_Grave..SunFA_Cedilla - // keysyms::SunF36 => Key::F36 | Key::F11, - // keysyms::SunF37 => Key::F37 | Key::F12, + // keysyms::SunF36 => Action::F36 | Action::F11, + // keysyms::SunF37 => Action::F37 | Action::F12, - // keysyms::SunSys_Req => Key::PrintScreen, + // keysyms::SunSys_Req => Action::PrintScreen, // The next couple of xkb (until SunStop) are already handled. // SunPrint_Screen..SunPageDown // SunUndo..SunFront - keysyms::SUN_Copy => Key::Copy, - keysyms::SUN_Open => Key::Open, - keysyms::SUN_Paste => Key::Paste, - keysyms::SUN_Cut => Key::Cut, + keysyms::SUN_Copy => Action::Copy, + keysyms::SUN_Open => Action::Open, + keysyms::SUN_Paste => Action::Paste, + keysyms::SUN_Cut => Action::Cut, // SunPowerSwitch - keysyms::SUN_AudioLowerVolume => Key::AudioVolumeDown, - keysyms::SUN_AudioMute => Key::AudioVolumeMute, - keysyms::SUN_AudioRaiseVolume => Key::AudioVolumeUp, + keysyms::SUN_AudioLowerVolume => Action::AudioVolumeDown, + keysyms::SUN_AudioMute => Action::AudioVolumeMute, + keysyms::SUN_AudioRaiseVolume => Action::AudioVolumeUp, // SUN_VideoDegauss - keysyms::SUN_VideoLowerBrightness => Key::BrightnessDown, - keysyms::SUN_VideoRaiseBrightness => Key::BrightnessUp, + keysyms::SUN_VideoLowerBrightness => Action::BrightnessDown, + keysyms::SUN_VideoRaiseBrightness => Action::BrightnessUp, // SunPowerSwitchShift // - 0 => Key::Unidentified(NativeKey::Unidentified), - _ => Key::Unidentified(NativeKey::Xkb(keysym)), - } + 0 => return Key::Unidentified(NativeKey::Unidentified), + _ => return Key::Unidentified(NativeKey::Xkb(keysym)), + }) } pub fn keysym_location(keysym: u32) -> KeyLocation { diff --git a/src/platform_impl/macos/event.rs b/src/platform_impl/macos/event.rs index db1c61657b..67cc683be2 100644 --- a/src/platform_impl/macos/event.rs +++ b/src/platform_impl/macos/event.rs @@ -11,7 +11,7 @@ use super::appkit::{NSEvent, NSEventModifierFlags}; use crate::{ event::{ElementState, KeyEvent, Modifiers}, keyboard::{ - Key, KeyCode, KeyLocation, ModifiersKeys, ModifiersState, NativeKey, NativeKeyCode, + Action, Key, KeyCode, KeyLocation, ModifiersKeys, ModifiersState, NativeKey, NativeKeyCode, PhysicalKey, }, platform::{ @@ -198,61 +198,61 @@ pub fn code_to_key(key: PhysicalKey, scancode: u16) -> Key { PhysicalKey::Unidentified(code) => return Key::Unidentified(code.into()), }; - match code { - KeyCode::Enter => Key::Enter, - KeyCode::Tab => Key::Tab, - KeyCode::Space => Key::Space, - KeyCode::Backspace => Key::Backspace, - KeyCode::Escape => Key::Escape, - KeyCode::SuperRight => Key::Super, - KeyCode::SuperLeft => Key::Super, - KeyCode::ShiftLeft => Key::Shift, - KeyCode::AltLeft => Key::Alt, - KeyCode::ControlLeft => Key::Control, - KeyCode::ShiftRight => Key::Shift, - KeyCode::AltRight => Key::Alt, - KeyCode::ControlRight => Key::Control, - - KeyCode::NumLock => Key::NumLock, - KeyCode::AudioVolumeUp => Key::AudioVolumeUp, - KeyCode::AudioVolumeDown => Key::AudioVolumeDown, + Key::Action(match code { + KeyCode::Enter => Action::Enter, + KeyCode::Tab => Action::Tab, + KeyCode::Space => Action::Space, + KeyCode::Backspace => Action::Backspace, + KeyCode::Escape => Action::Escape, + KeyCode::SuperRight => Action::Super, + KeyCode::SuperLeft => Action::Super, + KeyCode::ShiftLeft => Action::Shift, + KeyCode::AltLeft => Action::Alt, + KeyCode::ControlLeft => Action::Control, + KeyCode::ShiftRight => Action::Shift, + KeyCode::AltRight => Action::Alt, + KeyCode::ControlRight => Action::Control, + + KeyCode::NumLock => Action::NumLock, + KeyCode::AudioVolumeUp => Action::AudioVolumeUp, + KeyCode::AudioVolumeDown => Action::AudioVolumeDown, // Other numpad keys all generate text on macOS (if I understand correctly) - KeyCode::NumpadEnter => Key::Enter, - - KeyCode::F1 => Key::F1, - KeyCode::F2 => Key::F2, - KeyCode::F3 => Key::F3, - KeyCode::F4 => Key::F4, - KeyCode::F5 => Key::F5, - KeyCode::F6 => Key::F6, - KeyCode::F7 => Key::F7, - KeyCode::F8 => Key::F8, - KeyCode::F9 => Key::F9, - KeyCode::F10 => Key::F10, - KeyCode::F11 => Key::F11, - KeyCode::F12 => Key::F12, - KeyCode::F13 => Key::F13, - KeyCode::F14 => Key::F14, - KeyCode::F15 => Key::F15, - KeyCode::F16 => Key::F16, - KeyCode::F17 => Key::F17, - KeyCode::F18 => Key::F18, - KeyCode::F19 => Key::F19, - KeyCode::F20 => Key::F20, - - KeyCode::Insert => Key::Insert, - KeyCode::Home => Key::Home, - KeyCode::PageUp => Key::PageUp, - KeyCode::Delete => Key::Delete, - KeyCode::End => Key::End, - KeyCode::PageDown => Key::PageDown, - KeyCode::ArrowLeft => Key::ArrowLeft, - KeyCode::ArrowRight => Key::ArrowRight, - KeyCode::ArrowDown => Key::ArrowDown, - KeyCode::ArrowUp => Key::ArrowUp, - _ => Key::Unidentified(NativeKey::MacOS(scancode)), - } + KeyCode::NumpadEnter => Action::Enter, + + KeyCode::F1 => Action::F1, + KeyCode::F2 => Action::F2, + KeyCode::F3 => Action::F3, + KeyCode::F4 => Action::F4, + KeyCode::F5 => Action::F5, + KeyCode::F6 => Action::F6, + KeyCode::F7 => Action::F7, + KeyCode::F8 => Action::F8, + KeyCode::F9 => Action::F9, + KeyCode::F10 => Action::F10, + KeyCode::F11 => Action::F11, + KeyCode::F12 => Action::F12, + KeyCode::F13 => Action::F13, + KeyCode::F14 => Action::F14, + KeyCode::F15 => Action::F15, + KeyCode::F16 => Action::F16, + KeyCode::F17 => Action::F17, + KeyCode::F18 => Action::F18, + KeyCode::F19 => Action::F19, + KeyCode::F20 => Action::F20, + + KeyCode::Insert => Action::Insert, + KeyCode::Home => Action::Home, + KeyCode::PageUp => Action::PageUp, + KeyCode::Delete => Action::Delete, + KeyCode::End => Action::End, + KeyCode::PageDown => Action::PageDown, + KeyCode::ArrowLeft => Action::ArrowLeft, + KeyCode::ArrowRight => Action::ArrowRight, + KeyCode::ArrowDown => Action::ArrowDown, + KeyCode::ArrowUp => Action::ArrowUp, + _ => return Key::Unidentified(NativeKey::MacOS(scancode)), + }) } pub fn code_to_location(key: PhysicalKey) -> KeyLocation { diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index eb9ed3684c..c1036c0aa0 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -26,7 +26,7 @@ use crate::{ DeviceEvent, ElementState, Event, Ime, Modifiers, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent, }, - keyboard::{Key, KeyCode, KeyLocation, ModifiersState, PhysicalKey}, + keyboard::{Action, Key, KeyCode, KeyLocation, ModifiersState, PhysicalKey}, platform::macos::{OptionAsAlt, WindowExtMacOS}, platform::scancode::PhysicalKeyExtScancode, platform_impl::platform::{ @@ -90,30 +90,30 @@ impl ModLocationMask { fn key_to_modifier(key: &Key) -> ModifiersState { match key { - Key::Alt => ModifiersState::ALT, - Key::Control => ModifiersState::CONTROL, - Key::Super => ModifiersState::SUPER, - Key::Shift => ModifiersState::SHIFT, + Key::Action(Action::Alt) => ModifiersState::ALT, + Key::Action(Action::Control) => ModifiersState::CONTROL, + Key::Action(Action::Super) => ModifiersState::SUPER, + Key::Action(Action::Shift) => ModifiersState::SHIFT, _ => unreachable!(), } } fn get_right_modifier_code(key: &Key) -> KeyCode { match key { - Key::Alt => KeyCode::AltRight, - Key::Control => KeyCode::ControlRight, - Key::Shift => KeyCode::ShiftRight, - Key::Super => KeyCode::SuperRight, + Key::Action(Action::Alt) => KeyCode::AltRight, + Key::Action(Action::Control) => KeyCode::ControlRight, + Key::Action(Action::Shift) => KeyCode::ShiftRight, + Key::Action(Action::Super) => KeyCode::SuperRight, _ => unreachable!(), } } fn get_left_modifier_code(key: &Key) -> KeyCode { match key { - Key::Alt => KeyCode::AltLeft, - Key::Control => KeyCode::ControlLeft, - Key::Shift => KeyCode::ShiftLeft, - Key::Super => KeyCode::SuperLeft, + Key::Action(Action::Alt) => KeyCode::AltLeft, + Key::Action(Action::Control) => KeyCode::ControlLeft, + Key::Action(Action::Shift) => KeyCode::ShiftLeft, + Key::Action(Action::Super) => KeyCode::SuperLeft, _ => unreachable!(), } } diff --git a/src/platform_impl/web/keyboard.rs b/src/platform_impl/web/keyboard.rs index b7841cc725..abf4124228 100644 --- a/src/platform_impl/web/keyboard.rs +++ b/src/platform_impl/web/keyboard.rs @@ -1,322 +1,322 @@ use smol_str::SmolStr; -use crate::keyboard::{Key, KeyCode, NativeKey, NativeKeyCode, PhysicalKey}; +use crate::keyboard::{Action, Key, KeyCode, NativeKey, NativeKeyCode, PhysicalKey}; #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub(crate) struct KeyEventExtra; impl Key { pub(crate) fn from_key_attribute_value(kav: &str) -> Self { - match kav { - "Unidentified" => Key::Unidentified(NativeKey::Web(SmolStr::new(kav))), - "Dead" => Key::Dead(None), - "Alt" => Key::Alt, - "AltGraph" => Key::AltGraph, - "CapsLock" => Key::CapsLock, - "Control" => Key::Control, - "Fn" => Key::Fn, - "FnLock" => Key::FnLock, - "NumLock" => Key::NumLock, - "ScrollLock" => Key::ScrollLock, - "Shift" => Key::Shift, - "Symbol" => Key::Symbol, - "SymbolLock" => Key::SymbolLock, - "Hyper" => Key::Hyper, - "Meta" => Key::Super, - "Enter" => Key::Enter, - "Tab" => Key::Tab, - " " => Key::Space, - "ArrowDown" => Key::ArrowDown, - "ArrowLeft" => Key::ArrowLeft, - "ArrowRight" => Key::ArrowRight, - "ArrowUp" => Key::ArrowUp, - "End" => Key::End, - "Home" => Key::Home, - "PageDown" => Key::PageDown, - "PageUp" => Key::PageUp, - "Backspace" => Key::Backspace, - "Clear" => Key::Clear, - "Copy" => Key::Copy, - "CrSel" => Key::CrSel, - "Cut" => Key::Cut, - "Delete" => Key::Delete, - "EraseEof" => Key::EraseEof, - "ExSel" => Key::ExSel, - "Insert" => Key::Insert, - "Paste" => Key::Paste, - "Redo" => Key::Redo, - "Undo" => Key::Undo, - "Accept" => Key::Accept, - "Again" => Key::Again, - "Attn" => Key::Attn, - "Cancel" => Key::Cancel, - "ContextMenu" => Key::ContextMenu, - "Escape" => Key::Escape, - "Execute" => Key::Execute, - "Find" => Key::Find, - "Help" => Key::Help, - "Pause" => Key::Pause, - "Play" => Key::Play, - "Props" => Key::Props, - "Select" => Key::Select, - "ZoomIn" => Key::ZoomIn, - "ZoomOut" => Key::ZoomOut, - "BrightnessDown" => Key::BrightnessDown, - "BrightnessUp" => Key::BrightnessUp, - "Eject" => Key::Eject, - "LogOff" => Key::LogOff, - "Power" => Key::Power, - "PowerOff" => Key::PowerOff, - "PrintScreen" => Key::PrintScreen, - "Hibernate" => Key::Hibernate, - "Standby" => Key::Standby, - "WakeUp" => Key::WakeUp, - "AllCandidates" => Key::AllCandidates, - "Alphanumeric" => Key::Alphanumeric, - "CodeInput" => Key::CodeInput, - "Compose" => Key::Compose, - "Convert" => Key::Convert, - "FinalMode" => Key::FinalMode, - "GroupFirst" => Key::GroupFirst, - "GroupLast" => Key::GroupLast, - "GroupNext" => Key::GroupNext, - "GroupPrevious" => Key::GroupPrevious, - "ModeChange" => Key::ModeChange, - "NextCandidate" => Key::NextCandidate, - "NonConvert" => Key::NonConvert, - "PreviousCandidate" => Key::PreviousCandidate, - "Process" => Key::Process, - "SingleCandidate" => Key::SingleCandidate, - "HangulMode" => Key::HangulMode, - "HanjaMode" => Key::HanjaMode, - "JunjaMode" => Key::JunjaMode, - "Eisu" => Key::Eisu, - "Hankaku" => Key::Hankaku, - "Hiragana" => Key::Hiragana, - "HiraganaKatakana" => Key::HiraganaKatakana, - "KanaMode" => Key::KanaMode, - "KanjiMode" => Key::KanjiMode, - "Katakana" => Key::Katakana, - "Romaji" => Key::Romaji, - "Zenkaku" => Key::Zenkaku, - "ZenkakuHankaku" => Key::ZenkakuHankaku, - "Soft1" => Key::Soft1, - "Soft2" => Key::Soft2, - "Soft3" => Key::Soft3, - "Soft4" => Key::Soft4, - "ChannelDown" => Key::ChannelDown, - "ChannelUp" => Key::ChannelUp, - "Close" => Key::Close, - "MailForward" => Key::MailForward, - "MailReply" => Key::MailReply, - "MailSend" => Key::MailSend, - "MediaClose" => Key::MediaClose, - "MediaFastForward" => Key::MediaFastForward, - "MediaPause" => Key::MediaPause, - "MediaPlay" => Key::MediaPlay, - "MediaPlayPause" => Key::MediaPlayPause, - "MediaRecord" => Key::MediaRecord, - "MediaRewind" => Key::MediaRewind, - "MediaStop" => Key::MediaStop, - "MediaTrackNext" => Key::MediaTrackNext, - "MediaTrackPrevious" => Key::MediaTrackPrevious, - "New" => Key::New, - "Open" => Key::Open, - "Print" => Key::Print, - "Save" => Key::Save, - "SpellCheck" => Key::SpellCheck, - "Key11" => Key::Key11, - "Key12" => Key::Key12, - "AudioBalanceLeft" => Key::AudioBalanceLeft, - "AudioBalanceRight" => Key::AudioBalanceRight, - "AudioBassBoostDown" => Key::AudioBassBoostDown, - "AudioBassBoostToggle" => Key::AudioBassBoostToggle, - "AudioBassBoostUp" => Key::AudioBassBoostUp, - "AudioFaderFront" => Key::AudioFaderFront, - "AudioFaderRear" => Key::AudioFaderRear, - "AudioSurroundModeNext" => Key::AudioSurroundModeNext, - "AudioTrebleDown" => Key::AudioTrebleDown, - "AudioTrebleUp" => Key::AudioTrebleUp, - "AudioVolumeDown" => Key::AudioVolumeDown, - "AudioVolumeUp" => Key::AudioVolumeUp, - "AudioVolumeMute" => Key::AudioVolumeMute, - "MicrophoneToggle" => Key::MicrophoneToggle, - "MicrophoneVolumeDown" => Key::MicrophoneVolumeDown, - "MicrophoneVolumeUp" => Key::MicrophoneVolumeUp, - "MicrophoneVolumeMute" => Key::MicrophoneVolumeMute, - "SpeechCorrectionList" => Key::SpeechCorrectionList, - "SpeechInputToggle" => Key::SpeechInputToggle, - "LaunchApplication1" => Key::LaunchApplication1, - "LaunchApplication2" => Key::LaunchApplication2, - "LaunchCalendar" => Key::LaunchCalendar, - "LaunchContacts" => Key::LaunchContacts, - "LaunchMail" => Key::LaunchMail, - "LaunchMediaPlayer" => Key::LaunchMediaPlayer, - "LaunchMusicPlayer" => Key::LaunchMusicPlayer, - "LaunchPhone" => Key::LaunchPhone, - "LaunchScreenSaver" => Key::LaunchScreenSaver, - "LaunchSpreadsheet" => Key::LaunchSpreadsheet, - "LaunchWebBrowser" => Key::LaunchWebBrowser, - "LaunchWebCam" => Key::LaunchWebCam, - "LaunchWordProcessor" => Key::LaunchWordProcessor, - "BrowserBack" => Key::BrowserBack, - "BrowserFavorites" => Key::BrowserFavorites, - "BrowserForward" => Key::BrowserForward, - "BrowserHome" => Key::BrowserHome, - "BrowserRefresh" => Key::BrowserRefresh, - "BrowserSearch" => Key::BrowserSearch, - "BrowserStop" => Key::BrowserStop, - "AppSwitch" => Key::AppSwitch, - "Call" => Key::Call, - "Camera" => Key::Camera, - "CameraFocus" => Key::CameraFocus, - "EndCall" => Key::EndCall, - "GoBack" => Key::GoBack, - "GoHome" => Key::GoHome, - "HeadsetHook" => Key::HeadsetHook, - "LastNumberRedial" => Key::LastNumberRedial, - "Notification" => Key::Notification, - "MannerMode" => Key::MannerMode, - "VoiceDial" => Key::VoiceDial, - "TV" => Key::TV, - "TV3DMode" => Key::TV3DMode, - "TVAntennaCable" => Key::TVAntennaCable, - "TVAudioDescription" => Key::TVAudioDescription, - "TVAudioDescriptionMixDown" => Key::TVAudioDescriptionMixDown, - "TVAudioDescriptionMixUp" => Key::TVAudioDescriptionMixUp, - "TVContentsMenu" => Key::TVContentsMenu, - "TVDataService" => Key::TVDataService, - "TVInput" => Key::TVInput, - "TVInputComponent1" => Key::TVInputComponent1, - "TVInputComponent2" => Key::TVInputComponent2, - "TVInputComposite1" => Key::TVInputComposite1, - "TVInputComposite2" => Key::TVInputComposite2, - "TVInputHDMI1" => Key::TVInputHDMI1, - "TVInputHDMI2" => Key::TVInputHDMI2, - "TVInputHDMI3" => Key::TVInputHDMI3, - "TVInputHDMI4" => Key::TVInputHDMI4, - "TVInputVGA1" => Key::TVInputVGA1, - "TVMediaContext" => Key::TVMediaContext, - "TVNetwork" => Key::TVNetwork, - "TVNumberEntry" => Key::TVNumberEntry, - "TVPower" => Key::TVPower, - "TVRadioService" => Key::TVRadioService, - "TVSatellite" => Key::TVSatellite, - "TVSatelliteBS" => Key::TVSatelliteBS, - "TVSatelliteCS" => Key::TVSatelliteCS, - "TVSatelliteToggle" => Key::TVSatelliteToggle, - "TVTerrestrialAnalog" => Key::TVTerrestrialAnalog, - "TVTerrestrialDigital" => Key::TVTerrestrialDigital, - "TVTimer" => Key::TVTimer, - "AVRInput" => Key::AVRInput, - "AVRPower" => Key::AVRPower, - "ColorF0Red" => Key::ColorF0Red, - "ColorF1Green" => Key::ColorF1Green, - "ColorF2Yellow" => Key::ColorF2Yellow, - "ColorF3Blue" => Key::ColorF3Blue, - "ColorF4Grey" => Key::ColorF4Grey, - "ColorF5Brown" => Key::ColorF5Brown, - "ClosedCaptionToggle" => Key::ClosedCaptionToggle, - "Dimmer" => Key::Dimmer, - "DisplaySwap" => Key::DisplaySwap, - "DVR" => Key::DVR, - "Exit" => Key::Exit, - "FavoriteClear0" => Key::FavoriteClear0, - "FavoriteClear1" => Key::FavoriteClear1, - "FavoriteClear2" => Key::FavoriteClear2, - "FavoriteClear3" => Key::FavoriteClear3, - "FavoriteRecall0" => Key::FavoriteRecall0, - "FavoriteRecall1" => Key::FavoriteRecall1, - "FavoriteRecall2" => Key::FavoriteRecall2, - "FavoriteRecall3" => Key::FavoriteRecall3, - "FavoriteStore0" => Key::FavoriteStore0, - "FavoriteStore1" => Key::FavoriteStore1, - "FavoriteStore2" => Key::FavoriteStore2, - "FavoriteStore3" => Key::FavoriteStore3, - "Guide" => Key::Guide, - "GuideNextDay" => Key::GuideNextDay, - "GuidePreviousDay" => Key::GuidePreviousDay, - "Info" => Key::Info, - "InstantReplay" => Key::InstantReplay, - "Link" => Key::Link, - "ListProgram" => Key::ListProgram, - "LiveContent" => Key::LiveContent, - "Lock" => Key::Lock, - "MediaApps" => Key::MediaApps, - "MediaAudioTrack" => Key::MediaAudioTrack, - "MediaLast" => Key::MediaLast, - "MediaSkipBackward" => Key::MediaSkipBackward, - "MediaSkipForward" => Key::MediaSkipForward, - "MediaStepBackward" => Key::MediaStepBackward, - "MediaStepForward" => Key::MediaStepForward, - "MediaTopMenu" => Key::MediaTopMenu, - "NavigateIn" => Key::NavigateIn, - "NavigateNext" => Key::NavigateNext, - "NavigateOut" => Key::NavigateOut, - "NavigatePrevious" => Key::NavigatePrevious, - "NextFavoriteChannel" => Key::NextFavoriteChannel, - "NextUserProfile" => Key::NextUserProfile, - "OnDemand" => Key::OnDemand, - "Pairing" => Key::Pairing, - "PinPDown" => Key::PinPDown, - "PinPMove" => Key::PinPMove, - "PinPToggle" => Key::PinPToggle, - "PinPUp" => Key::PinPUp, - "PlaySpeedDown" => Key::PlaySpeedDown, - "PlaySpeedReset" => Key::PlaySpeedReset, - "PlaySpeedUp" => Key::PlaySpeedUp, - "RandomToggle" => Key::RandomToggle, - "RcLowBattery" => Key::RcLowBattery, - "RecordSpeedNext" => Key::RecordSpeedNext, - "RfBypass" => Key::RfBypass, - "ScanChannelsToggle" => Key::ScanChannelsToggle, - "ScreenModeNext" => Key::ScreenModeNext, - "Settings" => Key::Settings, - "SplitScreenToggle" => Key::SplitScreenToggle, - "STBInput" => Key::STBInput, - "STBPower" => Key::STBPower, - "Subtitle" => Key::Subtitle, - "Teletext" => Key::Teletext, - "VideoModeNext" => Key::VideoModeNext, - "Wink" => Key::Wink, - "ZoomToggle" => Key::ZoomToggle, - "F1" => Key::F1, - "F2" => Key::F2, - "F3" => Key::F3, - "F4" => Key::F4, - "F5" => Key::F5, - "F6" => Key::F6, - "F7" => Key::F7, - "F8" => Key::F8, - "F9" => Key::F9, - "F10" => Key::F10, - "F11" => Key::F11, - "F12" => Key::F12, - "F13" => Key::F13, - "F14" => Key::F14, - "F15" => Key::F15, - "F16" => Key::F16, - "F17" => Key::F17, - "F18" => Key::F18, - "F19" => Key::F19, - "F20" => Key::F20, - "F21" => Key::F21, - "F22" => Key::F22, - "F23" => Key::F23, - "F24" => Key::F24, - "F25" => Key::F25, - "F26" => Key::F26, - "F27" => Key::F27, - "F28" => Key::F28, - "F29" => Key::F29, - "F30" => Key::F30, - "F31" => Key::F31, - "F32" => Key::F32, - "F33" => Key::F33, - "F34" => Key::F34, - "F35" => Key::F35, - string => Key::Character(SmolStr::new(string)), - } + Key::Action(match kav { + "Unidentified" => return Key::Unidentified(NativeKey::Web(SmolStr::new(kav))), + "Dead" => return Key::Dead(None), + "Alt" => Action::Alt, + "AltGraph" => Action::AltGraph, + "CapsLock" => Action::CapsLock, + "Control" => Action::Control, + "Fn" => Action::Fn, + "FnLock" => Action::FnLock, + "NumLock" => Action::NumLock, + "ScrollLock" => Action::ScrollLock, + "Shift" => Action::Shift, + "Symbol" => Action::Symbol, + "SymbolLock" => Action::SymbolLock, + "Hyper" => Action::Hyper, + "Meta" => Action::Super, + "Enter" => Action::Enter, + "Tab" => Action::Tab, + " " => Action::Space, + "ArrowDown" => Action::ArrowDown, + "ArrowLeft" => Action::ArrowLeft, + "ArrowRight" => Action::ArrowRight, + "ArrowUp" => Action::ArrowUp, + "End" => Action::End, + "Home" => Action::Home, + "PageDown" => Action::PageDown, + "PageUp" => Action::PageUp, + "Backspace" => Action::Backspace, + "Clear" => Action::Clear, + "Copy" => Action::Copy, + "CrSel" => Action::CrSel, + "Cut" => Action::Cut, + "Delete" => Action::Delete, + "EraseEof" => Action::EraseEof, + "ExSel" => Action::ExSel, + "Insert" => Action::Insert, + "Paste" => Action::Paste, + "Redo" => Action::Redo, + "Undo" => Action::Undo, + "Accept" => Action::Accept, + "Again" => Action::Again, + "Attn" => Action::Attn, + "Cancel" => Action::Cancel, + "ContextMenu" => Action::ContextMenu, + "Escape" => Action::Escape, + "Execute" => Action::Execute, + "Find" => Action::Find, + "Help" => Action::Help, + "Pause" => Action::Pause, + "Play" => Action::Play, + "Props" => Action::Props, + "Select" => Action::Select, + "ZoomIn" => Action::ZoomIn, + "ZoomOut" => Action::ZoomOut, + "BrightnessDown" => Action::BrightnessDown, + "BrightnessUp" => Action::BrightnessUp, + "Eject" => Action::Eject, + "LogOff" => Action::LogOff, + "Power" => Action::Power, + "PowerOff" => Action::PowerOff, + "PrintScreen" => Action::PrintScreen, + "Hibernate" => Action::Hibernate, + "Standby" => Action::Standby, + "WakeUp" => Action::WakeUp, + "AllCandidates" => Action::AllCandidates, + "Alphanumeric" => Action::Alphanumeric, + "CodeInput" => Action::CodeInput, + "Compose" => Action::Compose, + "Convert" => Action::Convert, + "FinalMode" => Action::FinalMode, + "GroupFirst" => Action::GroupFirst, + "GroupLast" => Action::GroupLast, + "GroupNext" => Action::GroupNext, + "GroupPrevious" => Action::GroupPrevious, + "ModeChange" => Action::ModeChange, + "NextCandidate" => Action::NextCandidate, + "NonConvert" => Action::NonConvert, + "PreviousCandidate" => Action::PreviousCandidate, + "Process" => Action::Process, + "SingleCandidate" => Action::SingleCandidate, + "HangulMode" => Action::HangulMode, + "HanjaMode" => Action::HanjaMode, + "JunjaMode" => Action::JunjaMode, + "Eisu" => Action::Eisu, + "Hankaku" => Action::Hankaku, + "Hiragana" => Action::Hiragana, + "HiraganaKatakana" => Action::HiraganaKatakana, + "KanaMode" => Action::KanaMode, + "KanjiMode" => Action::KanjiMode, + "Katakana" => Action::Katakana, + "Romaji" => Action::Romaji, + "Zenkaku" => Action::Zenkaku, + "ZenkakuHankaku" => Action::ZenkakuHankaku, + "Soft1" => Action::Soft1, + "Soft2" => Action::Soft2, + "Soft3" => Action::Soft3, + "Soft4" => Action::Soft4, + "ChannelDown" => Action::ChannelDown, + "ChannelUp" => Action::ChannelUp, + "Close" => Action::Close, + "MailForward" => Action::MailForward, + "MailReply" => Action::MailReply, + "MailSend" => Action::MailSend, + "MediaClose" => Action::MediaClose, + "MediaFastForward" => Action::MediaFastForward, + "MediaPause" => Action::MediaPause, + "MediaPlay" => Action::MediaPlay, + "MediaPlayPause" => Action::MediaPlayPause, + "MediaRecord" => Action::MediaRecord, + "MediaRewind" => Action::MediaRewind, + "MediaStop" => Action::MediaStop, + "MediaTrackNext" => Action::MediaTrackNext, + "MediaTrackPrevious" => Action::MediaTrackPrevious, + "New" => Action::New, + "Open" => Action::Open, + "Print" => Action::Print, + "Save" => Action::Save, + "SpellCheck" => Action::SpellCheck, + "Key11" => Action::Key11, + "Key12" => Action::Key12, + "AudioBalanceLeft" => Action::AudioBalanceLeft, + "AudioBalanceRight" => Action::AudioBalanceRight, + "AudioBassBoostDown" => Action::AudioBassBoostDown, + "AudioBassBoostToggle" => Action::AudioBassBoostToggle, + "AudioBassBoostUp" => Action::AudioBassBoostUp, + "AudioFaderFront" => Action::AudioFaderFront, + "AudioFaderRear" => Action::AudioFaderRear, + "AudioSurroundModeNext" => Action::AudioSurroundModeNext, + "AudioTrebleDown" => Action::AudioTrebleDown, + "AudioTrebleUp" => Action::AudioTrebleUp, + "AudioVolumeDown" => Action::AudioVolumeDown, + "AudioVolumeUp" => Action::AudioVolumeUp, + "AudioVolumeMute" => Action::AudioVolumeMute, + "MicrophoneToggle" => Action::MicrophoneToggle, + "MicrophoneVolumeDown" => Action::MicrophoneVolumeDown, + "MicrophoneVolumeUp" => Action::MicrophoneVolumeUp, + "MicrophoneVolumeMute" => Action::MicrophoneVolumeMute, + "SpeechCorrectionList" => Action::SpeechCorrectionList, + "SpeechInputToggle" => Action::SpeechInputToggle, + "LaunchApplication1" => Action::LaunchApplication1, + "LaunchApplication2" => Action::LaunchApplication2, + "LaunchCalendar" => Action::LaunchCalendar, + "LaunchContacts" => Action::LaunchContacts, + "LaunchMail" => Action::LaunchMail, + "LaunchMediaPlayer" => Action::LaunchMediaPlayer, + "LaunchMusicPlayer" => Action::LaunchMusicPlayer, + "LaunchPhone" => Action::LaunchPhone, + "LaunchScreenSaver" => Action::LaunchScreenSaver, + "LaunchSpreadsheet" => Action::LaunchSpreadsheet, + "LaunchWebBrowser" => Action::LaunchWebBrowser, + "LaunchWebCam" => Action::LaunchWebCam, + "LaunchWordProcessor" => Action::LaunchWordProcessor, + "BrowserBack" => Action::BrowserBack, + "BrowserFavorites" => Action::BrowserFavorites, + "BrowserForward" => Action::BrowserForward, + "BrowserHome" => Action::BrowserHome, + "BrowserRefresh" => Action::BrowserRefresh, + "BrowserSearch" => Action::BrowserSearch, + "BrowserStop" => Action::BrowserStop, + "AppSwitch" => Action::AppSwitch, + "Call" => Action::Call, + "Camera" => Action::Camera, + "CameraFocus" => Action::CameraFocus, + "EndCall" => Action::EndCall, + "GoBack" => Action::GoBack, + "GoHome" => Action::GoHome, + "HeadsetHook" => Action::HeadsetHook, + "LastNumberRedial" => Action::LastNumberRedial, + "Notification" => Action::Notification, + "MannerMode" => Action::MannerMode, + "VoiceDial" => Action::VoiceDial, + "TV" => Action::TV, + "TV3DMode" => Action::TV3DMode, + "TVAntennaCable" => Action::TVAntennaCable, + "TVAudioDescription" => Action::TVAudioDescription, + "TVAudioDescriptionMixDown" => Action::TVAudioDescriptionMixDown, + "TVAudioDescriptionMixUp" => Action::TVAudioDescriptionMixUp, + "TVContentsMenu" => Action::TVContentsMenu, + "TVDataService" => Action::TVDataService, + "TVInput" => Action::TVInput, + "TVInputComponent1" => Action::TVInputComponent1, + "TVInputComponent2" => Action::TVInputComponent2, + "TVInputComposite1" => Action::TVInputComposite1, + "TVInputComposite2" => Action::TVInputComposite2, + "TVInputHDMI1" => Action::TVInputHDMI1, + "TVInputHDMI2" => Action::TVInputHDMI2, + "TVInputHDMI3" => Action::TVInputHDMI3, + "TVInputHDMI4" => Action::TVInputHDMI4, + "TVInputVGA1" => Action::TVInputVGA1, + "TVMediaContext" => Action::TVMediaContext, + "TVNetwork" => Action::TVNetwork, + "TVNumberEntry" => Action::TVNumberEntry, + "TVPower" => Action::TVPower, + "TVRadioService" => Action::TVRadioService, + "TVSatellite" => Action::TVSatellite, + "TVSatelliteBS" => Action::TVSatelliteBS, + "TVSatelliteCS" => Action::TVSatelliteCS, + "TVSatelliteToggle" => Action::TVSatelliteToggle, + "TVTerrestrialAnalog" => Action::TVTerrestrialAnalog, + "TVTerrestrialDigital" => Action::TVTerrestrialDigital, + "TVTimer" => Action::TVTimer, + "AVRInput" => Action::AVRInput, + "AVRPower" => Action::AVRPower, + "ColorF0Red" => Action::ColorF0Red, + "ColorF1Green" => Action::ColorF1Green, + "ColorF2Yellow" => Action::ColorF2Yellow, + "ColorF3Blue" => Action::ColorF3Blue, + "ColorF4Grey" => Action::ColorF4Grey, + "ColorF5Brown" => Action::ColorF5Brown, + "ClosedCaptionToggle" => Action::ClosedCaptionToggle, + "Dimmer" => Action::Dimmer, + "DisplaySwap" => Action::DisplaySwap, + "DVR" => Action::DVR, + "Exit" => Action::Exit, + "FavoriteClear0" => Action::FavoriteClear0, + "FavoriteClear1" => Action::FavoriteClear1, + "FavoriteClear2" => Action::FavoriteClear2, + "FavoriteClear3" => Action::FavoriteClear3, + "FavoriteRecall0" => Action::FavoriteRecall0, + "FavoriteRecall1" => Action::FavoriteRecall1, + "FavoriteRecall2" => Action::FavoriteRecall2, + "FavoriteRecall3" => Action::FavoriteRecall3, + "FavoriteStore0" => Action::FavoriteStore0, + "FavoriteStore1" => Action::FavoriteStore1, + "FavoriteStore2" => Action::FavoriteStore2, + "FavoriteStore3" => Action::FavoriteStore3, + "Guide" => Action::Guide, + "GuideNextDay" => Action::GuideNextDay, + "GuidePreviousDay" => Action::GuidePreviousDay, + "Info" => Action::Info, + "InstantReplay" => Action::InstantReplay, + "Link" => Action::Link, + "ListProgram" => Action::ListProgram, + "LiveContent" => Action::LiveContent, + "Lock" => Action::Lock, + "MediaApps" => Action::MediaApps, + "MediaAudioTrack" => Action::MediaAudioTrack, + "MediaLast" => Action::MediaLast, + "MediaSkipBackward" => Action::MediaSkipBackward, + "MediaSkipForward" => Action::MediaSkipForward, + "MediaStepBackward" => Action::MediaStepBackward, + "MediaStepForward" => Action::MediaStepForward, + "MediaTopMenu" => Action::MediaTopMenu, + "NavigateIn" => Action::NavigateIn, + "NavigateNext" => Action::NavigateNext, + "NavigateOut" => Action::NavigateOut, + "NavigatePrevious" => Action::NavigatePrevious, + "NextFavoriteChannel" => Action::NextFavoriteChannel, + "NextUserProfile" => Action::NextUserProfile, + "OnDemand" => Action::OnDemand, + "Pairing" => Action::Pairing, + "PinPDown" => Action::PinPDown, + "PinPMove" => Action::PinPMove, + "PinPToggle" => Action::PinPToggle, + "PinPUp" => Action::PinPUp, + "PlaySpeedDown" => Action::PlaySpeedDown, + "PlaySpeedReset" => Action::PlaySpeedReset, + "PlaySpeedUp" => Action::PlaySpeedUp, + "RandomToggle" => Action::RandomToggle, + "RcLowBattery" => Action::RcLowBattery, + "RecordSpeedNext" => Action::RecordSpeedNext, + "RfBypass" => Action::RfBypass, + "ScanChannelsToggle" => Action::ScanChannelsToggle, + "ScreenModeNext" => Action::ScreenModeNext, + "Settings" => Action::Settings, + "SplitScreenToggle" => Action::SplitScreenToggle, + "STBInput" => Action::STBInput, + "STBPower" => Action::STBPower, + "Subtitle" => Action::Subtitle, + "Teletext" => Action::Teletext, + "VideoModeNext" => Action::VideoModeNext, + "Wink" => Action::Wink, + "ZoomToggle" => Action::ZoomToggle, + "F1" => Action::F1, + "F2" => Action::F2, + "F3" => Action::F3, + "F4" => Action::F4, + "F5" => Action::F5, + "F6" => Action::F6, + "F7" => Action::F7, + "F8" => Action::F8, + "F9" => Action::F9, + "F10" => Action::F10, + "F11" => Action::F11, + "F12" => Action::F12, + "F13" => Action::F13, + "F14" => Action::F14, + "F15" => Action::F15, + "F16" => Action::F16, + "F17" => Action::F17, + "F18" => Action::F18, + "F19" => Action::F19, + "F20" => Action::F20, + "F21" => Action::F21, + "F22" => Action::F22, + "F23" => Action::F23, + "F24" => Action::F24, + "F25" => Action::F25, + "F26" => Action::F26, + "F27" => Action::F27, + "F28" => Action::F28, + "F29" => Action::F29, + "F30" => Action::F30, + "F31" => Action::F31, + "F32" => Action::F32, + "F33" => Action::F33, + "F34" => Action::F34, + "F35" => Action::F35, + string => return Key::Character(SmolStr::new(string)), + }) } } diff --git a/src/platform_impl/web/web_sys/event.rs b/src/platform_impl/web/web_sys/event.rs index 2e0c8be5f1..bdd6d58999 100644 --- a/src/platform_impl/web/web_sys/event.rs +++ b/src/platform_impl/web/web_sys/event.rs @@ -1,6 +1,6 @@ use crate::dpi::LogicalPosition; use crate::event::{MouseButton, MouseScrollDelta}; -use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; +use crate::keyboard::{Action, Key, KeyLocation, ModifiersState, PhysicalKey}; use once_cell::unsync::OnceCell; use smol_str::SmolStr; @@ -163,9 +163,9 @@ pub fn key_text(event: &KeyboardEvent) -> Option { let key = Key::from_key_attribute_value(&key); match &key { Key::Character(text) => Some(text.clone()), - Key::Tab => Some(SmolStr::new("\t")), - Key::Enter => Some(SmolStr::new("\r")), - Key::Space => Some(SmolStr::new(" ")), + Key::Action(Action::Tab) => Some(SmolStr::new("\t")), + Key::Action(Action::Enter) => Some(SmolStr::new("\r")), + Key::Action(Action::Space) => Some(SmolStr::new(" ")), _ => None, } .map(SmolStr::new) diff --git a/src/platform_impl/windows/keyboard.rs b/src/platform_impl/windows/keyboard.rs index 1aed1f5fc4..235b635f33 100644 --- a/src/platform_impl/windows/keyboard.rs +++ b/src/platform_impl/windows/keyboard.rs @@ -37,7 +37,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::{ event::{ElementState, KeyEvent}, - keyboard::{Key, KeyCode, KeyLocation, NativeKey, NativeKeyCode, PhysicalKey}, + keyboard::{Action, Key, KeyCode, KeyLocation, NativeKey, NativeKeyCode, PhysicalKey}, platform::scancode::PhysicalKeyExtScancode, platform_impl::platform::{ event_loop::ProcResult, @@ -560,8 +560,8 @@ impl PartialKeyEventInfo { // https://devblogs.microsoft.com/oldnewthing/20080211-00/?p=23503 let code_as_key = if mods.contains(WindowsModifiers::CONTROL) { match physical_key { - PhysicalKey::Code(KeyCode::NumLock) => Some(Key::NumLock), - PhysicalKey::Code(KeyCode::Pause) => Some(Key::Pause), + PhysicalKey::Code(KeyCode::NumLock) => Some(Key::Action(Action::NumLock)), + PhysicalKey::Code(KeyCode::Pause) => Some(Key::Action(Action::Pause)), _ => None, } } else { @@ -742,7 +742,10 @@ fn get_async_kbd_state() -> [u8; 256] { /// the next event is a right Alt (AltGr) event. If this is the case, the current event must be the /// fake Ctrl event. fn is_current_fake(curr_info: &PartialKeyEventInfo, next_msg: MSG, layout: &Layout) -> bool { - let curr_is_ctrl = matches!(curr_info.logical_key, PartialLogicalKey::This(Key::Control)); + let curr_is_ctrl = matches!( + curr_info.logical_key, + PartialLogicalKey::This(Key::Action(Action::Control)) + ); if layout.has_alt_graph { let next_code = ex_scancode_from_lparam(next_msg.lParam); let next_is_altgr = next_code == 0xE038; // 0xE038 is right alt diff --git a/src/platform_impl/windows/keyboard_layout.rs b/src/platform_impl/windows/keyboard_layout.rs index 24e8e9a9b9..6fa4ad179a 100644 --- a/src/platform_impl/windows/keyboard_layout.rs +++ b/src/platform_impl/windows/keyboard_layout.rs @@ -52,7 +52,7 @@ use windows_sys::Win32::{ }; use crate::{ - keyboard::{Key, KeyCode, ModifiersState, NativeKey, PhysicalKey}, + keyboard::{Action, Key, KeyCode, ModifiersState, NativeKey, PhysicalKey}, platform::scancode::PhysicalKeyExtScancode, platform_impl::{loword, primarylangid}, }; @@ -456,7 +456,7 @@ impl LayoutCache { let mod_state = WindowsModifiers::from_bits_retain(mod_state); if let Some(keys) = layout.keys.get_mut(&mod_state) { if let Some(key) = keys.get_mut(&KeyCode::AltRight) { - *key = Key::AltGraph; + *key = Key::Action(Action::AltGraph); } } } @@ -779,56 +779,56 @@ fn vkey_to_non_char_key( VK_MBUTTON => Key::Unidentified(NativeKey::Unidentified), // Mouse VK_XBUTTON1 => Key::Unidentified(NativeKey::Unidentified), // Mouse VK_XBUTTON2 => Key::Unidentified(NativeKey::Unidentified), // Mouse - VK_BACK => Key::Backspace, - VK_TAB => Key::Tab, - VK_CLEAR => Key::Clear, - VK_RETURN => Key::Enter, - VK_SHIFT => Key::Shift, - VK_CONTROL => Key::Control, - VK_MENU => Key::Alt, - VK_PAUSE => Key::Pause, - VK_CAPITAL => Key::CapsLock, - - //VK_HANGEUL => Key::HangulMode, // Deprecated in favour of VK_HANGUL + VK_BACK => Key::Action(Action::Backspace), + VK_TAB => Key::Action(Action::Tab), + VK_CLEAR => Key::Action(Action::Clear), + VK_RETURN => Key::Action(Action::Enter), + VK_SHIFT => Key::Action(Action::Shift), + VK_CONTROL => Key::Action(Action::Control), + VK_MENU => Key::Action(Action::Alt), + VK_PAUSE => Key::Action(Action::Pause), + VK_CAPITAL => Key::Action(Action::CapsLock), + + //VK_HANGEUL => Key::Action(Action::HangulMode), // Deprecated in favour of VK_HANGUL // VK_HANGUL and VK_KANA are defined as the same constant, therefore // we use appropriate conditions to differentate between them - VK_HANGUL if is_korean => Key::HangulMode, - VK_KANA if is_japanese => Key::KanaMode, + VK_HANGUL if is_korean => Key::Action(Action::HangulMode), + VK_KANA if is_japanese => Key::Action(Action::KanaMode), - VK_JUNJA => Key::JunjaMode, - VK_FINAL => Key::FinalMode, + VK_JUNJA => Key::Action(Action::JunjaMode), + VK_FINAL => Key::Action(Action::FinalMode), // VK_HANJA and VK_KANJI are defined as the same constant, therefore // we use appropriate conditions to differentate between them - VK_HANJA if is_korean => Key::HanjaMode, - VK_KANJI if is_japanese => Key::KanjiMode, - - VK_ESCAPE => Key::Escape, - VK_CONVERT => Key::Convert, - VK_NONCONVERT => Key::NonConvert, - VK_ACCEPT => Key::Accept, - VK_MODECHANGE => Key::ModeChange, - VK_SPACE => Key::Space, - VK_PRIOR => Key::PageUp, - VK_NEXT => Key::PageDown, - VK_END => Key::End, - VK_HOME => Key::Home, - VK_LEFT => Key::ArrowLeft, - VK_UP => Key::ArrowUp, - VK_RIGHT => Key::ArrowRight, - VK_DOWN => Key::ArrowDown, - VK_SELECT => Key::Select, - VK_PRINT => Key::Print, - VK_EXECUTE => Key::Execute, - VK_SNAPSHOT => Key::PrintScreen, - VK_INSERT => Key::Insert, - VK_DELETE => Key::Delete, - VK_HELP => Key::Help, - VK_LWIN => Key::Super, - VK_RWIN => Key::Super, - VK_APPS => Key::ContextMenu, - VK_SLEEP => Key::Standby, + VK_HANJA if is_korean => Key::Action(Action::HanjaMode), + VK_KANJI if is_japanese => Key::Action(Action::KanjiMode), + + VK_ESCAPE => Key::Action(Action::Escape), + VK_CONVERT => Key::Action(Action::Convert), + VK_NONCONVERT => Key::Action(Action::NonConvert), + VK_ACCEPT => Key::Action(Action::Accept), + VK_MODECHANGE => Key::Action(Action::ModeChange), + VK_SPACE => Key::Action(Action::Space), + VK_PRIOR => Key::Action(Action::PageUp), + VK_NEXT => Key::Action(Action::PageDown), + VK_END => Key::Action(Action::End), + VK_HOME => Key::Action(Action::Home), + VK_LEFT => Key::Action(Action::ArrowLeft), + VK_UP => Key::Action(Action::ArrowUp), + VK_RIGHT => Key::Action(Action::ArrowRight), + VK_DOWN => Key::Action(Action::ArrowDown), + VK_SELECT => Key::Action(Action::Select), + VK_PRINT => Key::Action(Action::Print), + VK_EXECUTE => Key::Action(Action::Execute), + VK_SNAPSHOT => Key::Action(Action::PrintScreen), + VK_INSERT => Key::Action(Action::Insert), + VK_DELETE => Key::Action(Action::Delete), + VK_HELP => Key::Action(Action::Help), + VK_LWIN => Key::Action(Action::Super), + VK_RWIN => Key::Action(Action::Super), + VK_APPS => Key::Action(Action::ContextMenu), + VK_SLEEP => Key::Action(Action::Standby), // Numpad keys produce characters VK_NUMPAD0 => Key::Unidentified(native_code), @@ -848,30 +848,30 @@ fn vkey_to_non_char_key( VK_DECIMAL => Key::Unidentified(native_code), VK_DIVIDE => Key::Unidentified(native_code), - VK_F1 => Key::F1, - VK_F2 => Key::F2, - VK_F3 => Key::F3, - VK_F4 => Key::F4, - VK_F5 => Key::F5, - VK_F6 => Key::F6, - VK_F7 => Key::F7, - VK_F8 => Key::F8, - VK_F9 => Key::F9, - VK_F10 => Key::F10, - VK_F11 => Key::F11, - VK_F12 => Key::F12, - VK_F13 => Key::F13, - VK_F14 => Key::F14, - VK_F15 => Key::F15, - VK_F16 => Key::F16, - VK_F17 => Key::F17, - VK_F18 => Key::F18, - VK_F19 => Key::F19, - VK_F20 => Key::F20, - VK_F21 => Key::F21, - VK_F22 => Key::F22, - VK_F23 => Key::F23, - VK_F24 => Key::F24, + VK_F1 => Key::Action(Action::F1), + VK_F2 => Key::Action(Action::F2), + VK_F3 => Key::Action(Action::F3), + VK_F4 => Key::Action(Action::F4), + VK_F5 => Key::Action(Action::F5), + VK_F6 => Key::Action(Action::F6), + VK_F7 => Key::Action(Action::F7), + VK_F8 => Key::Action(Action::F8), + VK_F9 => Key::Action(Action::F9), + VK_F10 => Key::Action(Action::F10), + VK_F11 => Key::Action(Action::F11), + VK_F12 => Key::Action(Action::F12), + VK_F13 => Key::Action(Action::F13), + VK_F14 => Key::Action(Action::F14), + VK_F15 => Key::Action(Action::F15), + VK_F16 => Key::Action(Action::F16), + VK_F17 => Key::Action(Action::F17), + VK_F18 => Key::Action(Action::F18), + VK_F19 => Key::Action(Action::F19), + VK_F20 => Key::Action(Action::F20), + VK_F21 => Key::Action(Action::F21), + VK_F22 => Key::Action(Action::F22), + VK_F23 => Key::Action(Action::F23), + VK_F24 => Key::Action(Action::F24), VK_NAVIGATION_VIEW => Key::Unidentified(native_code), VK_NAVIGATION_MENU => Key::Unidentified(native_code), VK_NAVIGATION_UP => Key::Unidentified(native_code), @@ -880,44 +880,44 @@ fn vkey_to_non_char_key( VK_NAVIGATION_RIGHT => Key::Unidentified(native_code), VK_NAVIGATION_ACCEPT => Key::Unidentified(native_code), VK_NAVIGATION_CANCEL => Key::Unidentified(native_code), - VK_NUMLOCK => Key::NumLock, - VK_SCROLL => Key::ScrollLock, + VK_NUMLOCK => Key::Action(Action::NumLock), + VK_SCROLL => Key::Action(Action::ScrollLock), VK_OEM_NEC_EQUAL => Key::Unidentified(native_code), //VK_OEM_FJ_JISHO => Key::Unidentified(native_code), // Conflicts with `VK_OEM_NEC_EQUAL` VK_OEM_FJ_MASSHOU => Key::Unidentified(native_code), VK_OEM_FJ_TOUROKU => Key::Unidentified(native_code), VK_OEM_FJ_LOYA => Key::Unidentified(native_code), VK_OEM_FJ_ROYA => Key::Unidentified(native_code), - VK_LSHIFT => Key::Shift, - VK_RSHIFT => Key::Shift, - VK_LCONTROL => Key::Control, - VK_RCONTROL => Key::Control, - VK_LMENU => Key::Alt, + VK_LSHIFT => Key::Action(Action::Shift), + VK_RSHIFT => Key::Action(Action::Shift), + VK_LCONTROL => Key::Action(Action::Control), + VK_RCONTROL => Key::Action(Action::Control), + VK_LMENU => Key::Action(Action::Alt), VK_RMENU => { if has_alt_graph { - Key::AltGraph + Key::Action(Action::AltGraph) } else { - Key::Alt + Key::Action(Action::Alt) } } - VK_BROWSER_BACK => Key::BrowserBack, - VK_BROWSER_FORWARD => Key::BrowserForward, - VK_BROWSER_REFRESH => Key::BrowserRefresh, - VK_BROWSER_STOP => Key::BrowserStop, - VK_BROWSER_SEARCH => Key::BrowserSearch, - VK_BROWSER_FAVORITES => Key::BrowserFavorites, - VK_BROWSER_HOME => Key::BrowserHome, - VK_VOLUME_MUTE => Key::AudioVolumeMute, - VK_VOLUME_DOWN => Key::AudioVolumeDown, - VK_VOLUME_UP => Key::AudioVolumeUp, - VK_MEDIA_NEXT_TRACK => Key::MediaTrackNext, - VK_MEDIA_PREV_TRACK => Key::MediaTrackPrevious, - VK_MEDIA_STOP => Key::MediaStop, - VK_MEDIA_PLAY_PAUSE => Key::MediaPlayPause, - VK_LAUNCH_MAIL => Key::LaunchMail, - VK_LAUNCH_MEDIA_SELECT => Key::LaunchMediaPlayer, - VK_LAUNCH_APP1 => Key::LaunchApplication1, - VK_LAUNCH_APP2 => Key::LaunchApplication2, + VK_BROWSER_BACK => Key::Action(Action::BrowserBack), + VK_BROWSER_FORWARD => Key::Action(Action::BrowserForward), + VK_BROWSER_REFRESH => Key::Action(Action::BrowserRefresh), + VK_BROWSER_STOP => Key::Action(Action::BrowserStop), + VK_BROWSER_SEARCH => Key::Action(Action::BrowserSearch), + VK_BROWSER_FAVORITES => Key::Action(Action::BrowserFavorites), + VK_BROWSER_HOME => Key::Action(Action::BrowserHome), + VK_VOLUME_MUTE => Key::Action(Action::AudioVolumeMute), + VK_VOLUME_DOWN => Key::Action(Action::AudioVolumeDown), + VK_VOLUME_UP => Key::Action(Action::AudioVolumeUp), + VK_MEDIA_NEXT_TRACK => Key::Action(Action::MediaTrackNext), + VK_MEDIA_PREV_TRACK => Key::Action(Action::MediaTrackPrevious), + VK_MEDIA_STOP => Key::Action(Action::MediaStop), + VK_MEDIA_PLAY_PAUSE => Key::Action(Action::MediaPlayPause), + VK_LAUNCH_MAIL => Key::Action(Action::LaunchMail), + VK_LAUNCH_MEDIA_SELECT => Key::Action(Action::LaunchMediaPlayer), + VK_LAUNCH_APP1 => Key::Action(Action::LaunchApplication1), + VK_LAUNCH_APP2 => Key::Action(Action::LaunchApplication2), // This function only converts "non-printable" VK_OEM_1 => Key::Unidentified(native_code), @@ -965,7 +965,7 @@ fn vkey_to_non_char_key( VK_ICO_HELP => Key::Unidentified(native_code), VK_ICO_00 => Key::Unidentified(native_code), - VK_PROCESSKEY => Key::Process, + VK_PROCESSKEY => Key::Action(Action::Process), VK_ICO_CLEAR => Key::Unidentified(native_code), VK_PACKET => Key::Unidentified(native_code), @@ -977,32 +977,32 @@ fn vkey_to_non_char_key( VK_OEM_WSCTRL => Key::Unidentified(native_code), VK_OEM_CUSEL => Key::Unidentified(native_code), - VK_OEM_ATTN => Key::Attn, + VK_OEM_ATTN => Key::Action(Action::Attn), VK_OEM_FINISH => { if is_japanese { - Key::Katakana + Key::Action(Action::Katakana) } else { // This matches IE and Firefox behaviour according to // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - // At the time of writing, there is no `Key::Finish` variant as + // At the time of writing, there is no `Action::Finish` variant as // Finish is not mentionned at https://w3c.github.io/uievents-key/ // Also see: https://github.com/pyfisch/keyboard-types/issues/9 Key::Unidentified(native_code) } } - VK_OEM_COPY => Key::Copy, - VK_OEM_AUTO => Key::Hankaku, - VK_OEM_ENLW => Key::Zenkaku, - VK_OEM_BACKTAB => Key::Romaji, - VK_ATTN => Key::KanaMode, - VK_CRSEL => Key::CrSel, - VK_EXSEL => Key::ExSel, - VK_EREOF => Key::EraseEof, - VK_PLAY => Key::Play, - VK_ZOOM => Key::ZoomToggle, + VK_OEM_COPY => Key::Action(Action::Copy), + VK_OEM_AUTO => Key::Action(Action::Hankaku), + VK_OEM_ENLW => Key::Action(Action::Zenkaku), + VK_OEM_BACKTAB => Key::Action(Action::Romaji), + VK_ATTN => Key::Action(Action::KanaMode), + VK_CRSEL => Key::Action(Action::CrSel), + VK_EXSEL => Key::Action(Action::ExSel), + VK_EREOF => Key::Action(Action::EraseEof), + VK_PLAY => Key::Action(Action::Play), + VK_ZOOM => Key::Action(Action::ZoomToggle), VK_NONAME => Key::Unidentified(native_code), VK_PA1 => Key::Unidentified(native_code), - VK_OEM_CLEAR => Key::Clear, + VK_OEM_CLEAR => Key::Action(Action::Clear), _ => Key::Unidentified(native_code), } }