From 5d41067a054b6658cb991d9de6391361e83ed6d8 Mon Sep 17 00:00:00 2001 From: Erik Rigtorp Date: Thu, 19 Jan 2017 19:45:02 -0600 Subject: [PATCH] Implement KeyboardEvent ModifiersState for win32 --- src/platform/windows/callback.rs | 6 +++--- src/platform/windows/event.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/platform/windows/callback.rs b/src/platform/windows/callback.rs index 53f54875..e8330107 100644 --- a/src/platform/windows/callback.rs +++ b/src/platform/windows/callback.rs @@ -8,7 +8,7 @@ use std::os::windows::ffi::OsStringExt; use CursorState; use WindowEvent as Event; -use events::ModifersState; +use events::ModifiersState; use super::event; use super::WindowState; @@ -201,7 +201,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, user32::DefWindowProcW(window, msg, wparam, lparam) } else { let (scancode, vkey) = event::vkeycode_to_element(wparam, lparam); - send_event(window, KeyboardInput(Pressed, scancode, vkey, ModifersState::default())); + send_event(window, KeyboardInput(Pressed, scancode, vkey, event::get_key_mods())); 0 } }, @@ -210,7 +210,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, use events::WindowEvent::KeyboardInput; use events::ElementState::Released; let (scancode, vkey) = event::vkeycode_to_element(wparam, lparam); - send_event(window, KeyboardInput(Released, scancode, vkey, ModifersState::default())); + send_event(window, KeyboardInput(Released, scancode, vkey, event::get_key_mods())); 0 }, diff --git a/src/platform/windows/event.rs b/src/platform/windows/event.rs index a4de7503..699f05d1 100644 --- a/src/platform/windows/event.rs +++ b/src/platform/windows/event.rs @@ -1,10 +1,30 @@ use events::VirtualKeyCode; +use events::ModifiersState; use winapi; use user32; use ScanCode; const MAPVK_VSC_TO_VK_EX: u32 = 3; +pub fn get_key_mods() -> ModifiersState { + let mut mods = ModifiersState::default(); + unsafe { + if user32::GetKeyState(winapi::VK_SHIFT) & (1 << 15) == (1 << 15) { + mods.shift = true; + } + if user32::GetKeyState(winapi::VK_CONTROL) & (1 << 15) == (1 << 15) { + mods.ctrl = true; + } + if user32::GetKeyState(winapi::VK_MENU) & (1 << 15) == (1 << 15) { + mods.alt = true; + } + if (user32::GetKeyState(winapi::VK_LWIN) | user32::GetKeyState(winapi::VK_RWIN)) & (1 << 15) == (1 << 15) { + mods.logo = true; + } + } + mods +} + pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (ScanCode, Option) { let scancode = ((lparam >> 16) & 0xff) as u8; let extended = (lparam & 0x01000000) != 0;