diff --git a/.gitignore b/.gitignore index 96ef6c0b..284f3b5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target Cargo.lock + +/.idea diff --git a/Cargo.toml b/Cargo.toml index daeb4dac..27b182fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ categories = ["development-tools::testing", "api-bindings", "hardware-support"] license = "MIT" [dependencies] -serde = {version = "1.0", features = ["derive"], optional=true} +serde = { version = "1.0", features = ["derive"], optional = true } lazy_static = "1.4" [features] @@ -23,20 +23,26 @@ unstable_grab = ["evdev-rs", "epoll", "inotify"] [target.'cfg(target_os = "macos")'.dependencies] cocoa = "0.22" -core-graphics = {version = "0.19.0", features = ["highsierra"]} -core-foundation = {version = "0.7"} -core-foundation-sys = {version = "0.7"} +core-graphics = { version = "0.19.0", features = ["highsierra"] } +core-foundation = { version = "0.7" } +core-foundation-sys = { version = "0.7" } [target.'cfg(target_os = "linux")'.dependencies] libc = "0.2" -x11 = {version = "2.18", features = ["xlib", "xrecord", "xinput"]} -evdev-rs = {version = "0.4.0", optional=true} -epoll = {version = "4.1.0", optional=true} -inotify = {version = "0.8.2", default-features=false, optional=true} +x11 = { version = "2.18", features = ["xlib", "xrecord", "xinput"] } +evdev-rs = { version = "0.4.0", optional = true } +epoll = { version = "4.1.0", optional = true } +inotify = { version = "0.8.2", default-features = false, optional = true } [target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3", features = ["winuser", "errhandlingapi", "processthreadsapi"] } +windows-sys = { version = "0.45.0", features = [ + "Win32_UI_WindowsAndMessaging", + "Win32_Foundation", + "Win32_System_Threading", + "Win32_UI_Input_KeyboardAndMouse", + "Win32_UI_TextServices" +] } [dev-dependencies] serde_json = "1.0" @@ -44,7 +50,7 @@ serde_json = "1.0" # because that leads to unexpected behavior and flaky tests, so we need # to run thoses tests in sequence instead. serial_test = "0.4" -tokio = {version = "1.5", features=["sync", "macros", "rt-multi-thread"]} +tokio = { version = "1.5", features = ["sync", "macros", "rt-multi-thread"] } [[example]] name = "serialize" @@ -62,3 +68,8 @@ required-features = ["unstable_grab"] name = "grab" path = "tests/grab.rs" required-features = ["unstable_grab"] + +[profile.release] +lto = true +codegen-units = 1 +opt-level = 3 \ No newline at end of file diff --git a/examples/channel.rs b/examples/channel.rs index 5f7158ac..8d9c59dd 100644 --- a/examples/channel.rs +++ b/examples/channel.rs @@ -9,14 +9,14 @@ fn main() { listen(move |event| { schan .send(event) - .unwrap_or_else(|e| println!("Could not send event {:?}", e)); + .unwrap_or_else(|e| println!("Could not send event {e:?}")); }) .expect("Could not listen"); }); let mut events = Vec::new(); for event in rchan.iter() { - println!("Received {:?}", event); + println!("Received {event:?}"); events.push(event); } } diff --git a/examples/display.rs b/examples/display.rs index b51848a4..8cedc49d 100644 --- a/examples/display.rs +++ b/examples/display.rs @@ -2,5 +2,5 @@ use rdev::display_size; fn main() { let (w, h) = display_size().unwrap(); - println!("Your screen is {:?}x{:?}", w, h); + println!("Your screen is {w:?}x{h:?}"); } diff --git a/examples/keyboard_state.rs b/examples/keyboard_state.rs index 833eee96..9d4e19aa 100644 --- a/examples/keyboard_state.rs +++ b/examples/keyboard_state.rs @@ -4,13 +4,13 @@ fn main() { let mut keyboard = Keyboard::new().unwrap(); let char_s = keyboard.add(&EventType::KeyPress(Key::KeyS)).unwrap(); assert_eq!(char_s, "s".to_string()); - println!("Pressing S gives: {:?}", char_s); + println!("Pressing S gives: {char_s:?}"); let n = keyboard.add(&EventType::KeyRelease(Key::KeyS)); assert_eq!(n, None); keyboard.add(&EventType::KeyPress(Key::ShiftLeft)); let char_s = keyboard.add(&EventType::KeyPress(Key::KeyS)).unwrap(); - println!("Pressing Shift+S gives: {:?}", char_s); + println!("Pressing Shift+S gives: {char_s:?}"); assert_eq!(char_s, "S".to_string()); let n = keyboard.add(&EventType::KeyRelease(Key::KeyS)); assert_eq!(n, None); diff --git a/examples/listen.rs b/examples/listen.rs index 37852947..d38ef3ed 100644 --- a/examples/listen.rs +++ b/examples/listen.rs @@ -3,10 +3,10 @@ use rdev::{listen, Event}; fn main() { // This will block. if let Err(error) = listen(callback) { - println!("Error: {:?}", error) + println!("Error: {error:?}") } } fn callback(event: Event) { - println!("My callback {:?}", event); + println!("My callback {event:?}"); } diff --git a/examples/simulate.rs b/examples/simulate.rs index 1f50f042..9288213d 100644 --- a/examples/simulate.rs +++ b/examples/simulate.rs @@ -6,7 +6,7 @@ fn send(event_type: &EventType) { match simulate(event_type) { Ok(()) => (), Err(SimulateError) => { - println!("We could not send {:?}", event_type); + println!("We could not send {event_type:?}"); } } // Let ths OS catchup (at least MacOS) diff --git a/src/windows/common.rs b/src/windows/common.rs index a7579c52..671e809f 100644 --- a/src/windows/common.rs +++ b/src/windows/common.rs @@ -4,13 +4,12 @@ use crate::windows::keycodes::key_from_code; use lazy_static::lazy_static; use std::convert::TryInto; use std::os::raw::{c_int, c_short}; -use std::ptr::null_mut; + use std::sync::Mutex; -use winapi::shared::minwindef::{DWORD, HIWORD, LPARAM, LRESULT, WORD, WPARAM}; -use winapi::shared::ntdef::LONG; -use winapi::shared::windef::HHOOK; -use winapi::um::errhandlingapi::GetLastError; -use winapi::um::winuser::{ +use windows_sys::Win32::Foundation::GetLastError; +use windows_sys::Win32::Foundation::{LPARAM, LRESULT}; +use windows_sys::Win32::UI::WindowsAndMessaging::HHOOK; +use windows_sys::Win32::UI::WindowsAndMessaging::{ SetWindowsHookExA, KBDLLHOOKSTRUCT, MSLLHOOKSTRUCT, WHEEL_DELTA, WH_KEYBOARD_LL, WH_MOUSE_LL, WM_KEYDOWN, WM_KEYUP, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEHWHEEL, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_SYSKEYDOWN, @@ -19,36 +18,41 @@ use winapi::um::winuser::{ pub const TRUE: i32 = 1; pub const FALSE: i32 = 0; -pub static mut HOOK: HHOOK = null_mut(); +#[inline] +pub fn hiword(l: u32) -> u16 { + ((l >> 16) & 0xffff) as u16 +} + +pub static mut HOOK: HHOOK = 0; lazy_static! { pub(crate) static ref KEYBOARD: Mutex = Mutex::new(Keyboard::new().unwrap()); } -pub unsafe fn get_code(lpdata: LPARAM) -> DWORD { +pub unsafe fn get_code(lpdata: LPARAM) -> u32 { let kb = *(lpdata as *const KBDLLHOOKSTRUCT); kb.vkCode } -pub unsafe fn get_scan_code(lpdata: LPARAM) -> DWORD { +pub unsafe fn get_scan_code(lpdata: LPARAM) -> u32 { let kb = *(lpdata as *const KBDLLHOOKSTRUCT); kb.scanCode } -pub unsafe fn get_point(lpdata: LPARAM) -> (LONG, LONG) { +pub unsafe fn get_point(lpdata: LPARAM) -> (i32, i32) { let mouse = *(lpdata as *const MSLLHOOKSTRUCT); (mouse.pt.x, mouse.pt.y) } // https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644986(v=vs.85) -/// confusingly, this function returns a WORD (unsigned), but may be +/// confusingly, this function returns a u16 (unsigned), but may be /// interpreted as either signed or unsigned depending on context -pub unsafe fn get_delta(lpdata: LPARAM) -> WORD { +pub unsafe fn get_delta(lpdata: LPARAM) -> u16 { let mouse = *(lpdata as *const MSLLHOOKSTRUCT); - HIWORD(mouse.mouseData) + hiword(mouse.mouseData) } -pub unsafe fn get_button_code(lpdata: LPARAM) -> WORD { +pub unsafe fn get_button_code(lpdata: LPARAM) -> u16 { let mouse = *(lpdata as *const MSLLHOOKSTRUCT); - HIWORD(mouse.mouseData) + hiword(mouse.mouseData) } -pub unsafe fn convert(param: WPARAM, lpdata: LPARAM) -> Option { +pub unsafe fn convert(param: usize, lpdata: LPARAM) -> Option { match param.try_into() { Ok(WM_KEYDOWN) | Ok(WM_SYSKEYDOWN) => { let code = get_code(lpdata); @@ -85,13 +89,13 @@ pub unsafe fn convert(param: WPARAM, lpdata: LPARAM) -> Option { let delta = get_delta(lpdata) as c_short; Some(EventType::Wheel { delta_x: 0, - delta_y: (delta / WHEEL_DELTA) as i64, + delta_y: (delta as u32 / WHEEL_DELTA) as i64, }) } Ok(WM_MOUSEHWHEEL) => { let delta = get_delta(lpdata) as c_short; Some(EventType::Wheel { - delta_x: (delta / WHEEL_DELTA) as i64, + delta_x: (delta as u32 / WHEEL_DELTA) as i64, delta_y: 0, }) } @@ -99,16 +103,16 @@ pub unsafe fn convert(param: WPARAM, lpdata: LPARAM) -> Option { } } -type RawCallback = unsafe extern "system" fn(code: c_int, param: WPARAM, lpdata: LPARAM) -> LRESULT; +type RawCallback = unsafe extern "system" fn(code: c_int, param: usize, lpdata: LPARAM) -> LRESULT; pub enum HookError { - Mouse(DWORD), - Key(DWORD), + Mouse(u32), + Key(u32), } pub unsafe fn set_key_hook(callback: RawCallback) -> Result<(), HookError> { - let hook = SetWindowsHookExA(WH_KEYBOARD_LL, Some(callback), null_mut(), 0); + let hook = SetWindowsHookExA(WH_KEYBOARD_LL, Some(callback), 0, 0); - if hook.is_null() { + if hook == 0 { let error = GetLastError(); return Err(HookError::Key(error)); } @@ -117,8 +121,8 @@ pub unsafe fn set_key_hook(callback: RawCallback) -> Result<(), HookError> { } pub unsafe fn set_mouse_hook(callback: RawCallback) -> Result<(), HookError> { - let hook = SetWindowsHookExA(WH_MOUSE_LL, Some(callback), null_mut(), 0); - if hook.is_null() { + let hook = SetWindowsHookExA(WH_MOUSE_LL, Some(callback), 0, 0); + if hook == 0 { let error = GetLastError(); return Err(HookError::Mouse(error)); } diff --git a/src/windows/display.rs b/src/windows/display.rs index c7db82f6..3ab721c6 100644 --- a/src/windows/display.rs +++ b/src/windows/display.rs @@ -1,6 +1,6 @@ use crate::rdev::DisplayError; use std::convert::TryInto; -use winapi::um::winuser::{GetSystemMetrics, SM_CXSCREEN, SM_CYSCREEN}; +use windows_sys::Win32::UI::WindowsAndMessaging::{GetSystemMetrics, SM_CXSCREEN, SM_CYSCREEN}; pub fn display_size() -> Result<(u64, u64), DisplayError> { let w = unsafe { diff --git a/src/windows/grab.rs b/src/windows/grab.rs index cd1930f2..5430a84a 100644 --- a/src/windows/grab.rs +++ b/src/windows/grab.rs @@ -2,12 +2,12 @@ use crate::rdev::{Event, EventType, GrabError}; use crate::windows::common::{convert, set_key_hook, set_mouse_hook, HookError, HOOK, KEYBOARD}; use std::ptr::null_mut; use std::time::SystemTime; -use winapi::um::winuser::{CallNextHookEx, GetMessageA, HC_ACTION}; +use windows_sys::Win32::UI::WindowsAndMessaging::{CallNextHookEx, GetMessageA, HC_ACTION}; static mut GLOBAL_CALLBACK: Option Option>> = None; unsafe extern "system" fn raw_callback(code: i32, param: usize, lpdata: isize) -> isize { - if code == HC_ACTION { + if code == HC_ACTION as i32 { let opt = convert(param, lpdata); if let Some(event_type) = opt { let name = match &event_type { @@ -53,7 +53,7 @@ where set_key_hook(raw_callback)?; set_mouse_hook(raw_callback)?; - GetMessageA(null_mut(), null_mut(), 0, 0); + GetMessageA(null_mut(), 0, 0, 0); } Ok(()) } diff --git a/src/windows/keyboard.rs b/src/windows/keyboard.rs index 7eeb2753..b4b1b1fe 100644 --- a/src/windows/keyboard.rs +++ b/src/windows/keyboard.rs @@ -2,13 +2,15 @@ use crate::rdev::{EventType, Key, KeyboardState}; use crate::windows::common::{get_code, get_scan_code, FALSE, TRUE}; use crate::windows::keycodes::code_from_key; use std::ptr::null_mut; -use winapi::shared::minwindef::{BYTE, HKL, LPARAM, UINT}; -use winapi::um::processthreadsapi::GetCurrentThreadId; -use winapi::um::winuser; -use winapi::um::winuser::{ - GetForegroundWindow, GetKeyState, GetKeyboardLayout, GetKeyboardState, - GetWindowThreadProcessId, ToUnicodeEx, VK_CAPITAL, VK_LSHIFT, VK_RSHIFT, VK_SHIFT, +use windows_sys::Win32::Foundation::LPARAM; +use windows_sys::Win32::System::Threading::{AttachThreadInput, GetCurrentThreadId}; +use windows_sys::Win32::UI::Input::KeyboardAndMouse::{ + GetKeyState, GetKeyboardLayout, GetKeyboardState, ToUnicodeEx, VK_CAPITAL, VK_LSHIFT, + VK_RSHIFT, VK_SHIFT, }; +use windows_sys::Win32::UI::TextServices::HKL; + +use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId}; const VK_SHIFT_: usize = VK_SHIFT as usize; const VK_CAPITAL_: usize = VK_CAPITAL as usize; @@ -17,9 +19,9 @@ const VK_RSHIFT_: usize = VK_RSHIFT as usize; const HIGHBIT: u8 = 0x80; pub struct Keyboard { - last_code: UINT, - last_scan_code: UINT, - last_state: [BYTE; 256], + last_code: u32, + last_scan_code: u32, + last_state: [u8; 256], last_is_dead: bool, } @@ -47,16 +49,16 @@ impl Keyboard { let mut state = [0_u8; 256]; let state_ptr = state.as_mut_ptr(); - let _shift = GetKeyState(VK_SHIFT); + let _shift = GetKeyState(VK_SHIFT as i32); let current_window_thread_id = GetWindowThreadProcessId(GetForegroundWindow(), null_mut()); let thread_id = GetCurrentThreadId(); // Attach to active thread so we can get that keyboard state - let status = if winuser::AttachThreadInput(thread_id, current_window_thread_id, TRUE) == 1 { + let status = if AttachThreadInput(thread_id, current_window_thread_id, TRUE) == 1 { // Current state of the modifiers in keyboard let status = GetKeyboardState(state_ptr); // Detach - winuser::AttachThreadInput(thread_id, current_window_thread_id, FALSE); + AttachThreadInput(thread_id, current_window_thread_id, FALSE); status } else { // Could not attach, perhaps it is this process? @@ -70,7 +72,7 @@ impl Keyboard { Some(()) } - pub(crate) unsafe fn get_code_name(&mut self, code: UINT, scan_code: UINT) -> Option { + pub(crate) unsafe fn get_code_name(&mut self, code: u32, scan_code: u32) -> Option { let current_window_thread_id = GetWindowThreadProcessId(GetForegroundWindow(), null_mut()); let state_ptr = self.last_state.as_mut_ptr(); const BUF_LEN: i32 = 32; @@ -113,7 +115,7 @@ impl Keyboard { result } - unsafe fn clear_keyboard_buffer(&self, code: UINT, scan_code: UINT, layout: HKL) { + unsafe fn clear_keyboard_buffer(&self, code: u32, scan_code: u32, layout: HKL) { const BUF_LEN: i32 = 32; let mut buff = [0_u16; BUF_LEN as usize]; let buff_ptr = buff.as_mut_ptr(); diff --git a/src/windows/keycodes.rs b/src/windows/keycodes.rs index c3707f76..0db67c47 100644 --- a/src/windows/keycodes.rs +++ b/src/windows/keycodes.rs @@ -1,11 +1,10 @@ use crate::rdev::Key; use std::convert::TryInto; -use winapi::shared::minwindef::WORD; macro_rules! decl_keycodes { ($($key:ident, $code:literal),*) => { //TODO: make const when rust lang issue #49146 is fixed - pub fn code_from_key(key: Key) -> Option { + pub fn code_from_key(key: Key) -> Option { match key { $( Key::$key => Some($code), @@ -16,7 +15,7 @@ macro_rules! decl_keycodes { } //TODO: make const when rust lang issue #49146 is fixed - pub fn key_from_code(code: WORD) -> Key { + pub fn key_from_code(code: u16) -> Key { match code { $( $code => Key::$key, diff --git a/src/windows/listen.rs b/src/windows/listen.rs index bff00d2c..e240c684 100644 --- a/src/windows/listen.rs +++ b/src/windows/listen.rs @@ -3,8 +3,8 @@ use crate::windows::common::{convert, set_key_hook, set_mouse_hook, HookError, H use std::os::raw::c_int; use std::ptr::null_mut; use std::time::SystemTime; -use winapi::shared::minwindef::{LPARAM, LRESULT, WPARAM}; -use winapi::um::winuser::{CallNextHookEx, GetMessageA, HC_ACTION}; +use windows_sys::Win32::Foundation::{LPARAM, LRESULT, WPARAM}; +use windows_sys::Win32::UI::WindowsAndMessaging::{CallNextHookEx, GetMessageA, HC_ACTION}; static mut GLOBAL_CALLBACK: Option> = None; @@ -18,7 +18,7 @@ impl From for ListenError { } unsafe extern "system" fn raw_callback(code: c_int, param: WPARAM, lpdata: LPARAM) -> LRESULT { - if code == HC_ACTION { + if code == HC_ACTION as i32 { let opt = convert(param, lpdata); if let Some(event_type) = opt { let name = match &event_type { @@ -50,7 +50,7 @@ where set_key_hook(raw_callback)?; set_mouse_hook(raw_callback)?; - GetMessageA(null_mut(), null_mut(), 0, 0); + GetMessageA(null_mut(), 0, 0, 0); } Ok(()) } diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 8ef404f3..b58ecf0a 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -1,5 +1,3 @@ -extern crate winapi; - mod common; mod display; #[cfg(feature = "unstable_grab")] diff --git a/src/windows/simulate.rs b/src/windows/simulate.rs index cd62e220..d86c6060 100644 --- a/src/windows/simulate.rs +++ b/src/windows/simulate.rs @@ -2,40 +2,40 @@ use crate::rdev::{Button, EventType, SimulateError}; use crate::windows::keycodes::code_from_key; use std::convert::TryFrom; use std::mem::size_of; -use winapi::ctypes::{c_int, c_short}; -use winapi::shared::minwindef::{DWORD, UINT, WORD}; -use winapi::shared::ntdef::LONG; -use winapi::um::winuser::{ - GetSystemMetrics, INPUT_u, SendInput, INPUT, INPUT_KEYBOARD, INPUT_MOUSE, KEYBDINPUT, - KEYEVENTF_KEYUP, MOUSEEVENTF_ABSOLUTE, MOUSEEVENTF_HWHEEL, MOUSEEVENTF_LEFTDOWN, - MOUSEEVENTF_LEFTUP, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP, MOUSEEVENTF_MOVE, - MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP, MOUSEEVENTF_VIRTUALDESK, MOUSEEVENTF_WHEEL, - MOUSEEVENTF_XDOWN, MOUSEEVENTF_XUP, MOUSEINPUT, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, - WHEEL_DELTA, +use windows_sys::Win32::UI::WindowsAndMessaging::{ + GetSystemMetrics, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, WHEEL_DELTA, +}; + +use windows_sys::Win32::UI::Input::KeyboardAndMouse::{ + SendInput, INPUT, INPUT_0, INPUT_KEYBOARD, INPUT_MOUSE, KEYBDINPUT, KEYEVENTF_KEYUP, + MOUSEEVENTF_ABSOLUTE, MOUSEEVENTF_HWHEEL, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, + MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP, MOUSEEVENTF_MOVE, MOUSEEVENTF_RIGHTDOWN, + MOUSEEVENTF_RIGHTUP, MOUSEEVENTF_VIRTUALDESK, MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, + MOUSEEVENTF_XUP, MOUSEINPUT, }; /// Not defined in win32 but define here for clarity -static KEYEVENTF_KEYDOWN: DWORD = 0; +static KEYEVENTF_KEYDOWN: u32 = 0; -fn sim_mouse_event(flags: DWORD, data: DWORD, dx: LONG, dy: LONG) -> Result<(), SimulateError> { - let mut union: INPUT_u = unsafe { std::mem::zeroed() }; - let inner_union = unsafe { union.mi_mut() }; +fn sim_mouse_event(flags: u32, data: u32, dx: i32, dy: i32) -> Result<(), SimulateError> { + let mut union: INPUT_0 = unsafe { std::mem::zeroed() }; + let inner_union = unsafe { &mut union.mi }; *inner_union = MOUSEINPUT { dx, dy, - mouseData: data, + mouseData: data as i32, dwFlags: flags, time: 0, dwExtraInfo: 0, }; let mut input = [INPUT { - type_: INPUT_MOUSE, - u: union, + r#type: INPUT_MOUSE, + Anonymous: union, }; 1]; let value = unsafe { SendInput( - input.len() as UINT, + input.len() as u32, input.as_mut_ptr(), - size_of::() as c_int, + size_of::() as i32, ) }; if value != 1 { @@ -45,9 +45,9 @@ fn sim_mouse_event(flags: DWORD, data: DWORD, dx: LONG, dy: LONG) -> Result<(), } } -fn sim_keyboard_event(flags: DWORD, vk: WORD, scan: WORD) -> Result<(), SimulateError> { - let mut union: INPUT_u = unsafe { std::mem::zeroed() }; - let inner_union = unsafe { union.ki_mut() }; +fn sim_keyboard_event(flags: u32, vk: u16, scan: u16) -> Result<(), SimulateError> { + let mut union: INPUT_0 = unsafe { std::mem::zeroed() }; + let inner_union = unsafe { &mut union.ki }; *inner_union = KEYBDINPUT { wVk: vk, wScan: scan, @@ -56,14 +56,14 @@ fn sim_keyboard_event(flags: DWORD, vk: WORD, scan: WORD) -> Result<(), Simulate dwExtraInfo: 0, }; let mut input = [INPUT { - type_: INPUT_KEYBOARD, - u: union, + r#type: INPUT_KEYBOARD, + Anonymous: union, }; 1]; let value = unsafe { SendInput( - input.len() as UINT, + input.len() as u32, input.as_mut_ptr(), - size_of::() as c_int, + size_of::() as i32, ) }; if value != 1 { @@ -99,7 +99,7 @@ pub fn simulate(event_type: &EventType) -> Result<(), SimulateError> { if *delta_x != 0 { sim_mouse_event( MOUSEEVENTF_HWHEEL, - (c_short::try_from(*delta_x).map_err(|_| SimulateError)? * WHEEL_DELTA) as u32, + u32::try_from(*delta_x).map_err(|_| SimulateError)? * WHEEL_DELTA, 0, 0, )?; @@ -108,7 +108,7 @@ pub fn simulate(event_type: &EventType) -> Result<(), SimulateError> { if *delta_y != 0 { sim_mouse_event( MOUSEEVENTF_WHEEL, - (c_short::try_from(*delta_y).map_err(|_| SimulateError)? * WHEEL_DELTA) as u32, + u32::try_from(*delta_y).map_err(|_| SimulateError)? * WHEEL_DELTA, 0, 0, )?;