Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 6 additions & 6 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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)
}
Expand All @@ -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())
}
}