mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
add missing windows virtual key codes
This commit is contained in:
parent
cc89d56e43
commit
32eea41b1b
|
@ -3,7 +3,9 @@ use events::ModifiersState;
|
||||||
use winapi;
|
use winapi;
|
||||||
use user32;
|
use user32;
|
||||||
use ScanCode;
|
use ScanCode;
|
||||||
|
use std::char;
|
||||||
|
|
||||||
|
const MAPVK_VK_TO_CHAR: u32 = 2;
|
||||||
const MAPVK_VSC_TO_VK_EX: u32 = 3;
|
const MAPVK_VSC_TO_VK_EX: u32 = 3;
|
||||||
|
|
||||||
pub fn get_key_mods() -> ModifiersState {
|
pub fn get_key_mods() -> ModifiersState {
|
||||||
|
@ -34,6 +36,8 @@ pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (S
|
||||||
winapi::VK_MENU => if extended { winapi::VK_RMENU } else { winapi::VK_LMENU },
|
winapi::VK_MENU => if extended { winapi::VK_RMENU } else { winapi::VK_LMENU },
|
||||||
other => other
|
other => other
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// VK_* codes are documented here https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
|
||||||
(scancode, match vk {
|
(scancode, match vk {
|
||||||
//winapi::VK_LBUTTON => Some(VirtualKeyCode::Lbutton),
|
//winapi::VK_LBUTTON => Some(VirtualKeyCode::Lbutton),
|
||||||
//winapi::VK_RBUTTON => Some(VirtualKeyCode::Rbutton),
|
//winapi::VK_RBUTTON => Some(VirtualKeyCode::Rbutton),
|
||||||
|
@ -181,18 +185,18 @@ pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (S
|
||||||
winapi::VK_LAUNCH_MEDIA_SELECT => Some(VirtualKeyCode::MediaSelect),
|
winapi::VK_LAUNCH_MEDIA_SELECT => Some(VirtualKeyCode::MediaSelect),
|
||||||
/*winapi::VK_LAUNCH_APP1 => Some(VirtualKeyCode::Launch_app1),
|
/*winapi::VK_LAUNCH_APP1 => Some(VirtualKeyCode::Launch_app1),
|
||||||
winapi::VK_LAUNCH_APP2 => Some(VirtualKeyCode::Launch_app2),*/
|
winapi::VK_LAUNCH_APP2 => Some(VirtualKeyCode::Launch_app2),*/
|
||||||
winapi::VK_OEM_PLUS => Some(VirtualKeyCode::Equals),
|
winapi::VK_OEM_PLUS => Some(VirtualKeyCode::Equals),
|
||||||
winapi::VK_OEM_COMMA => Some(VirtualKeyCode::Comma),
|
winapi::VK_OEM_COMMA => Some(VirtualKeyCode::Comma),
|
||||||
winapi::VK_OEM_MINUS => Some(VirtualKeyCode::Minus),
|
winapi::VK_OEM_MINUS => Some(VirtualKeyCode::Minus),
|
||||||
winapi::VK_OEM_PERIOD => Some(VirtualKeyCode::Period),
|
winapi::VK_OEM_PERIOD => Some(VirtualKeyCode::Period),
|
||||||
/*winapi::VK_OEM_1 => Some(VirtualKeyCode::Oem_1),
|
winapi::VK_OEM_1 => map_text_keys(vk),
|
||||||
winapi::VK_OEM_2 => Some(VirtualKeyCode::Oem_2),
|
winapi::VK_OEM_2 => map_text_keys(vk),
|
||||||
winapi::VK_OEM_3 => Some(VirtualKeyCode::Oem_3),
|
winapi::VK_OEM_3 => map_text_keys(vk),
|
||||||
winapi::VK_OEM_4 => Some(VirtualKeyCode::Oem_4),
|
winapi::VK_OEM_4 => map_text_keys(vk),
|
||||||
winapi::VK_OEM_5 => Some(VirtualKeyCode::Oem_5),
|
winapi::VK_OEM_5 => map_text_keys(vk),
|
||||||
winapi::VK_OEM_6 => Some(VirtualKeyCode::Oem_6),
|
winapi::VK_OEM_6 => map_text_keys(vk),
|
||||||
winapi::VK_OEM_7 => Some(VirtualKeyCode::Oem_7),
|
winapi::VK_OEM_7 => map_text_keys(vk),
|
||||||
winapi::VK_OEM_8 => Some(VirtualKeyCode::Oem_8), */
|
/*winapi::VK_OEM_8 => Some(VirtualKeyCode::Oem_8), */
|
||||||
winapi::VK_OEM_102 => Some(VirtualKeyCode::OEM102),
|
winapi::VK_OEM_102 => Some(VirtualKeyCode::OEM102),
|
||||||
/*winapi::VK_PROCESSKEY => Some(VirtualKeyCode::Processkey),
|
/*winapi::VK_PROCESSKEY => Some(VirtualKeyCode::Processkey),
|
||||||
winapi::VK_PACKET => Some(VirtualKeyCode::Packet),
|
winapi::VK_PACKET => Some(VirtualKeyCode::Packet),
|
||||||
|
@ -208,3 +212,19 @@ pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (S
|
||||||
_ => None
|
_ => None
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is needed as windows doesn't properly distinguish
|
||||||
|
// some virtual key codes for different keyboard layouts
|
||||||
|
fn map_text_keys(win_virtual_key: i32) -> Option<VirtualKeyCode> {
|
||||||
|
let char_key = unsafe { user32::MapVirtualKeyA(win_virtual_key as u32, MAPVK_VK_TO_CHAR) } & 0x7FFF;
|
||||||
|
match char::from_u32(char_key) {
|
||||||
|
Some(';') => Some(VirtualKeyCode::Semicolon),
|
||||||
|
Some('/') => Some(VirtualKeyCode::Slash),
|
||||||
|
Some('`') => Some(VirtualKeyCode::Grave),
|
||||||
|
Some('[') => Some(VirtualKeyCode::LBracket),
|
||||||
|
Some(']') => Some(VirtualKeyCode::RBracket),
|
||||||
|
Some('\'') => Some(VirtualKeyCode::Apostrophe),
|
||||||
|
Some('\\') => Some(VirtualKeyCode::Backslash),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue