From d612a1b5a10cc63413b0d7026eedcdab78d2d181 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sun, 20 Sep 2020 12:58:24 +0300 Subject: [PATCH] Prefix numpad virtual key codes with Numpad This commit is a follow up to a2db4c0a320aafc10d240c432fe5ef4e4d84629d to make it clear which virtual key codes are located on numeric pad. It also adds Asterisk and Plus virtual key codes. --- CHANGELOG.md | 3 ++- src/event.rs | 10 ++++++---- src/platform_impl/linux/wayland/keyboard.rs | 12 ++++++------ src/platform_impl/linux/x11/events.rs | 12 ++++++------ src/platform_impl/macos/event.rs | 8 ++++---- src/platform_impl/web/stdweb/event.rs | 8 ++++---- src/platform_impl/web/web_sys/event.rs | 8 ++++---- src/platform_impl/windows/event.rs | 8 ++++---- 8 files changed, 36 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dce45aa1..0cc84b1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,6 @@ - **Breaking:** On Web, `set_cursor_position` and `set_cursor_grab` will now always return an error. - **Breaking:** `PixelDelta` scroll events now return a `PhysicalPosition`. - On NetBSD, fixed crash due to incorrect detection of the main thread. -- **Breaking:** The virtual key code `Subtract` has been renamed to `NumpadSubtract`. - **Breaking:** On X11, `-` key is mapped to the `Minus` virtual key code, instead of `Subtract`. - On macOS, fix inverted horizontal scroll. - **Breaking:** `current_monitor` now returns `Option`. @@ -33,6 +32,8 @@ - On macOS, updated core-* dependencies and cocoa. - Bump `parking_lot` to 0.11 - On Android, bump `ndk`, `ndk-sys` and `ndk-glue` to 0.2. Checkout the new ndk-glue main proc attribute. +- **Breaking:** Prefixed virtual key codes `Add`, `Multiply`, `Divide`, `Decimal`, and `Subtract` with `Numpad`. +- Added `Asterisk` and `Plus` virtual key codes. # 0.22.2 (2020-05-16) diff --git a/src/event.rs b/src/event.rs index 134421ac..5d89c7db 100644 --- a/src/event.rs +++ b/src/event.rs @@ -892,16 +892,20 @@ pub enum VirtualKeyCode { Numpad7, Numpad8, Numpad9, + NumpadAdd, + NumpadDivide, + NumpadDecimal, NumpadComma, NumpadEnter, NumpadEquals, + NumpadMultiply, NumpadSubtract, AbntC1, AbntC2, - Add, Apostrophe, Apps, + Asterisk, At, Ax, Backslash, @@ -910,8 +914,6 @@ pub enum VirtualKeyCode { Colon, Comma, Convert, - Decimal, - Divide, Equals, Grave, Kana, @@ -925,7 +927,6 @@ pub enum VirtualKeyCode { MediaSelect, MediaStop, Minus, - Multiply, Mute, MyComputer, // also called "Next" @@ -937,6 +938,7 @@ pub enum VirtualKeyCode { OEM102, Period, PlayPause, + Plus, Power, PrevTrack, RAlt, diff --git a/src/platform_impl/linux/wayland/keyboard.rs b/src/platform_impl/linux/wayland/keyboard.rs index fb9219e0..7c58e7c4 100644 --- a/src/platform_impl/linux/wayland/keyboard.rs +++ b/src/platform_impl/linux/wayland/keyboard.rs @@ -305,7 +305,7 @@ fn keysym_to_vkey(keysym: u32) -> Option { // misc // => Some(VirtualKeyCode::AbntC1), // => Some(VirtualKeyCode::AbntC2), - keysyms::XKB_KEY_plus => Some(VirtualKeyCode::Add), + keysyms::XKB_KEY_plus => Some(VirtualKeyCode::Plus), keysyms::XKB_KEY_apostrophe => Some(VirtualKeyCode::Apostrophe), // => Some(VirtualKeyCode::Apps), // => Some(VirtualKeyCode::At), @@ -316,8 +316,6 @@ fn keysym_to_vkey(keysym: u32) -> Option { keysyms::XKB_KEY_colon => Some(VirtualKeyCode::Colon), keysyms::XKB_KEY_comma => Some(VirtualKeyCode::Comma), // => Some(VirtualKeyCode::Convert), - // => Some(VirtualKeyCode::Decimal), - // => Some(VirtualKeyCode::Divide), keysyms::XKB_KEY_equal => Some(VirtualKeyCode::Equals), // => Some(VirtualKeyCode::Grave), // => Some(VirtualKeyCode::Kana), @@ -331,7 +329,7 @@ fn keysym_to_vkey(keysym: u32) -> Option { // => Some(VirtualKeyCode::MediaSelect), // => Some(VirtualKeyCode::MediaStop), keysyms::XKB_KEY_minus => Some(VirtualKeyCode::Minus), - keysyms::XKB_KEY_asterisk => Some(VirtualKeyCode::Multiply), + keysyms::XKB_KEY_asterisk => Some(VirtualKeyCode::Asterisk), // => Some(VirtualKeyCode::Mute), // => Some(VirtualKeyCode::MyComputer), // => Some(VirtualKeyCode::NextTrack), @@ -339,9 +337,11 @@ fn keysym_to_vkey(keysym: u32) -> Option { keysyms::XKB_KEY_KP_Separator => Some(VirtualKeyCode::NumpadComma), keysyms::XKB_KEY_KP_Enter => Some(VirtualKeyCode::NumpadEnter), keysyms::XKB_KEY_KP_Equal => Some(VirtualKeyCode::NumpadEquals), - keysyms::XKB_KEY_KP_Add => Some(VirtualKeyCode::Add), + keysyms::XKB_KEY_KP_Add => Some(VirtualKeyCode::NumpadAdd), keysyms::XKB_KEY_KP_Subtract => Some(VirtualKeyCode::NumpadSubtract), - keysyms::XKB_KEY_KP_Divide => Some(VirtualKeyCode::Divide), + keysyms::XKB_KEY_KP_Multiply => Some(VirtualKeyCode::NumpadMultiply), + keysyms::XKB_KEY_KP_Decimal => Some(VirtualKeyCode::NumpadDecimal), + keysyms::XKB_KEY_KP_Divide => Some(VirtualKeyCode::NumpadDivide), keysyms::XKB_KEY_KP_Page_Up => Some(VirtualKeyCode::PageUp), keysyms::XKB_KEY_KP_Page_Down => Some(VirtualKeyCode::PageDown), keysyms::XKB_KEY_KP_Home => Some(VirtualKeyCode::Home), diff --git a/src/platform_impl/linux/x11/events.rs b/src/platform_impl/linux/x11/events.rs index f7d98b98..0c02ca0c 100644 --- a/src/platform_impl/linux/x11/events.rs +++ b/src/platform_impl/linux/x11/events.rs @@ -81,12 +81,12 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option { ffi::XK_KP_Insert => VirtualKeyCode::Insert, ffi::XK_KP_Delete => VirtualKeyCode::Delete, ffi::XK_KP_Equal => VirtualKeyCode::NumpadEquals, - //ffi::XK_KP_Multiply => VirtualKeyCode::NumpadMultiply, - ffi::XK_KP_Add => VirtualKeyCode::Add, + ffi::XK_KP_Multiply => VirtualKeyCode::NumpadMultiply, + ffi::XK_KP_Add => VirtualKeyCode::NumpadAdd, //ffi::XK_KP_Separator => VirtualKeyCode::Kp_separator, ffi::XK_KP_Subtract => VirtualKeyCode::NumpadSubtract, - //ffi::XK_KP_Decimal => VirtualKeyCode::Kp_decimal, - ffi::XK_KP_Divide => VirtualKeyCode::Divide, + ffi::XK_KP_Decimal => VirtualKeyCode::NumpadDecimal, + ffi::XK_KP_Divide => VirtualKeyCode::NumpadDivide, ffi::XK_KP_0 => VirtualKeyCode::Numpad0, ffi::XK_KP_1 => VirtualKeyCode::Numpad1, ffi::XK_KP_2 => VirtualKeyCode::Numpad2, @@ -183,8 +183,8 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option { //ffi::XK_quoteright => VirtualKeyCode::Quoteright, //ffi::XK_parenleft => VirtualKeyCode::Parenleft, //ffi::XK_parenright => VirtualKeyCode::Parenright, - //ffi::XK_asterisk => VirtualKeyCode::Asterisk, - ffi::XK_plus => VirtualKeyCode::Add, + ffi::XK_asterisk => VirtualKeyCode::Asterisk, + ffi::XK_plus => VirtualKeyCode::Plus, ffi::XK_comma => VirtualKeyCode::Comma, ffi::XK_minus => VirtualKeyCode::Minus, ffi::XK_period => VirtualKeyCode::Period, diff --git a/src/platform_impl/macos/event.rs b/src/platform_impl/macos/event.rs index dd12c973..343aaeb2 100644 --- a/src/platform_impl/macos/event.rs +++ b/src/platform_impl/macos/event.rs @@ -156,17 +156,17 @@ pub fn scancode_to_keycode(scancode: c_ushort) -> Option { 0x3e => VirtualKeyCode::RControl, //0x3f => Fn key, 0x40 => VirtualKeyCode::F17, - 0x41 => VirtualKeyCode::Decimal, + 0x41 => VirtualKeyCode::NumpadDecimal, //0x42 -> unkown, - 0x43 => VirtualKeyCode::Multiply, + 0x43 => VirtualKeyCode::NumpadMultiply, //0x44 => unkown, - 0x45 => VirtualKeyCode::Add, + 0x45 => VirtualKeyCode::NumpadAdd, //0x46 => unkown, 0x47 => VirtualKeyCode::Numlock, //0x48 => KeypadClear, 0x49 => VirtualKeyCode::VolumeUp, 0x4a => VirtualKeyCode::VolumeDown, - 0x4b => VirtualKeyCode::Divide, + 0x4b => VirtualKeyCode::NumpadDivide, 0x4c => VirtualKeyCode::NumpadEnter, //0x4d => unkown, 0x4e => VirtualKeyCode::NumpadSubtract, diff --git a/src/platform_impl/web/stdweb/event.rs b/src/platform_impl/web/stdweb/event.rs index e9bb1b38..d04298af 100644 --- a/src/platform_impl/web/stdweb/event.rs +++ b/src/platform_impl/web/stdweb/event.rs @@ -146,7 +146,7 @@ pub fn virtual_key_code(event: &impl IKeyboardEvent) -> Option { "Numpad9" => VirtualKeyCode::Numpad9, "AbntC1" => VirtualKeyCode::AbntC1, "AbntC2" => VirtualKeyCode::AbntC2, - "NumpadAdd" => VirtualKeyCode::Add, + "NumpadAdd" => VirtualKeyCode::NumpadAdd, "Quote" => VirtualKeyCode::Apostrophe, "Apps" => VirtualKeyCode::Apps, "At" => VirtualKeyCode::At, @@ -157,8 +157,8 @@ pub fn virtual_key_code(event: &impl IKeyboardEvent) -> Option { "Semicolon" => VirtualKeyCode::Semicolon, "Comma" => VirtualKeyCode::Comma, "Convert" => VirtualKeyCode::Convert, - "NumpadDecimal" => VirtualKeyCode::Decimal, - "NumpadDivide" => VirtualKeyCode::Divide, + "NumpadDecimal" => VirtualKeyCode::NumpadDecimal, + "NumpadDivide" => VirtualKeyCode::NumpadDivide, "Equal" => VirtualKeyCode::Equals, "Backquote" => VirtualKeyCode::Grave, "Kana" => VirtualKeyCode::Kana, @@ -172,7 +172,7 @@ pub fn virtual_key_code(event: &impl IKeyboardEvent) -> Option { "MediaSelect" => VirtualKeyCode::MediaSelect, "MediaStop" => VirtualKeyCode::MediaStop, "Minus" => VirtualKeyCode::Minus, - "NumpadMultiply" => VirtualKeyCode::Multiply, + "NumpadMultiply" => VirtualKeyCode::NumpadMultiply, "Mute" => VirtualKeyCode::Mute, "LaunchMyComputer" => VirtualKeyCode::MyComputer, "NavigateForward" => VirtualKeyCode::NavigateForward, diff --git a/src/platform_impl/web/web_sys/event.rs b/src/platform_impl/web/web_sys/event.rs index 80291568..3d2b77b1 100644 --- a/src/platform_impl/web/web_sys/event.rs +++ b/src/platform_impl/web/web_sys/event.rs @@ -155,7 +155,7 @@ pub fn virtual_key_code(event: &KeyboardEvent) -> Option { "Numpad9" => VirtualKeyCode::Numpad9, "AbntC1" => VirtualKeyCode::AbntC1, "AbntC2" => VirtualKeyCode::AbntC2, - "NumpadAdd" => VirtualKeyCode::Add, + "NumpadAdd" => VirtualKeyCode::NumpadAdd, "Quote" => VirtualKeyCode::Apostrophe, "Apps" => VirtualKeyCode::Apps, "At" => VirtualKeyCode::At, @@ -166,8 +166,8 @@ pub fn virtual_key_code(event: &KeyboardEvent) -> Option { "Semicolon" => VirtualKeyCode::Semicolon, "Comma" => VirtualKeyCode::Comma, "Convert" => VirtualKeyCode::Convert, - "NumpadDecimal" => VirtualKeyCode::Decimal, - "NumpadDivide" => VirtualKeyCode::Divide, + "NumpadDecimal" => VirtualKeyCode::NumpadDecimal, + "NumpadDivide" => VirtualKeyCode::NumpadDivide, "Equal" => VirtualKeyCode::Equals, "Backquote" => VirtualKeyCode::Grave, "Kana" => VirtualKeyCode::Kana, @@ -181,7 +181,7 @@ pub fn virtual_key_code(event: &KeyboardEvent) -> Option { "MediaSelect" => VirtualKeyCode::MediaSelect, "MediaStop" => VirtualKeyCode::MediaStop, "Minus" => VirtualKeyCode::Minus, - "NumpadMultiply" => VirtualKeyCode::Multiply, + "NumpadMultiply" => VirtualKeyCode::NumpadMultiply, "Mute" => VirtualKeyCode::Mute, "LaunchMyComputer" => VirtualKeyCode::MyComputer, "NavigateForward" => VirtualKeyCode::NavigateForward, diff --git a/src/platform_impl/windows/event.rs b/src/platform_impl/windows/event.rs index 40312418..4b3b68d9 100644 --- a/src/platform_impl/windows/event.rs +++ b/src/platform_impl/windows/event.rs @@ -259,12 +259,12 @@ pub fn vkey_to_winit_vkey(vkey: c_int) -> Option { winuser::VK_NUMPAD7 => Some(VirtualKeyCode::Numpad7), winuser::VK_NUMPAD8 => Some(VirtualKeyCode::Numpad8), winuser::VK_NUMPAD9 => Some(VirtualKeyCode::Numpad9), - winuser::VK_MULTIPLY => Some(VirtualKeyCode::Multiply), - winuser::VK_ADD => Some(VirtualKeyCode::Add), + winuser::VK_MULTIPLY => Some(VirtualKeyCode::NumpadMultiply), + winuser::VK_ADD => Some(VirtualKeyCode::NumpadAdd), //winuser::VK_SEPARATOR => Some(VirtualKeyCode::Separator), winuser::VK_SUBTRACT => Some(VirtualKeyCode::NumpadSubtract), - winuser::VK_DECIMAL => Some(VirtualKeyCode::Decimal), - winuser::VK_DIVIDE => Some(VirtualKeyCode::Divide), + winuser::VK_DECIMAL => Some(VirtualKeyCode::NumpadDecimal), + winuser::VK_DIVIDE => Some(VirtualKeyCode::NumpadDivide), winuser::VK_F1 => Some(VirtualKeyCode::F1), winuser::VK_F2 => Some(VirtualKeyCode::F2), winuser::VK_F3 => Some(VirtualKeyCode::F3),