From 612b3aa581e0d4908d6eaf235d7d3f2fadb8397d Mon Sep 17 00:00:00 2001 From: Claude DevOps Engineer Date: Thu, 29 Jan 2026 04:05:00 -0300 Subject: [PATCH] Migrate from winapi 0.3 to windows 0.62 crate Replace deprecated winapi 0.3 with the official windows 0.62 crate. Adapt to strongly-typed wrappers: VK_* constants are now VIRTUAL_KEY (u16), KEYEVENTF_* flags are now KEYBD_EVENT_FLAGS (u32). Cast VIRTUAL_KEY.0 to u8 for keybd_event() and to i32 for GetKeyState(). Closes #10 --- Cargo.toml | 6 +++--- src/windows.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e34a0f4..cabeaf8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,9 @@ categories = [ edition = '2021' [dependencies] -[target."cfg(windows)".dependencies.winapi] -version = '0.3' -features = ['winuser'] +[target."cfg(windows)".dependencies.windows] +version = '0.62' +features = ['Win32_UI_Input_KeyboardAndMouse'] [target.'cfg(target_os = "macos")'.dependencies] core-foundation = '0.10' mach = '0.3' diff --git a/src/windows.rs b/src/windows.rs index 213dd52..0c0639e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,7 +1,6 @@ use std::ptr; -use winapi::shared::minwindef::BYTE; -use winapi::um::winuser::{ +use windows::Win32::UI::Input::KeyboardAndMouse::{ keybd_event, GetKeyState, KEYEVENTF_EXTENDEDKEY, KEYEVENTF_KEYUP, VK_CAPITAL, VK_NUMLOCK, VK_SCROLL, }; @@ -31,9 +30,10 @@ impl LockKeyWrapper for LockKey { /// Sets a new state for the lock key using [winuser API](https://docs.microsoft.com/en-us/windows/win32/api/winuser). fn set(&self, key: LockKeys, state: LockKeyState) -> LockKeyResult { unsafe { - let key = lock_key_to_vkkey!(key) as BYTE; - keybd_event(key, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0); - keybd_event(key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); + let vk = lock_key_to_vkkey!(key); + let key_byte = vk.0 as u8; + keybd_event(key_byte, 0x45, KEYEVENTF_EXTENDEDKEY, 0); + keybd_event(key_byte, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } Ok(state) } @@ -57,7 +57,7 @@ impl LockKeyWrapper for LockKey { /// Retrieves the lock key state using [winuser API](https://docs.microsoft.com/en-us/windows/win32/api/winuser). fn state(&self, key: LockKeys) -> LockKeyResult { - let key_state = unsafe { GetKeyState(lock_key_to_vkkey!(key)) == 1 }; + let key_state = unsafe { GetKeyState(lock_key_to_vkkey!(key).0 as i32) == 1 }; Ok(key_state.into()) } }