From 88c8e0354adcb28e53c948479a6abc7c0a6915ba Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 25 Nov 2020 13:51:11 +0900 Subject: [PATCH] ing --- src/mouse/windows/mod.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/mouse/windows/mod.rs b/src/mouse/windows/mod.rs index 3344fe1..e009926 100644 --- a/src/mouse/windows/mod.rs +++ b/src/mouse/windows/mod.rs @@ -2,20 +2,25 @@ use std::mem::{size_of, transmute}; use winapi::ctypes::c_int; use winapi::shared::minwindef::DWORD; use winapi::um::winuser::{ - GetAsyncKeyState, SendInput, INPUT, INPUT_MOUSE, LPINPUT, MOUSEEVENTF_ABSOLUTE, + GetAsyncKeyState, GetSystemMetrics, SendInput, INPUT, INPUT_MOUSE, LPINPUT, MOUSEEVENTF_ABSOLUTE, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP, MOUSEEVENTF_MOVE, MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP, MOUSEEVENTF_VIRTUALDESK, - MOUSEINPUT, VK_LBUTTON, VK_MBUTTON, VK_RBUTTON, VK_XBUTTON1, VK_XBUTTON2, + MOUSEINPUT, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN, + VK_LBUTTON, VK_MBUTTON, VK_RBUTTON, VK_XBUTTON1, VK_XBUTTON2, }; use crate::mouse::{Button, ButtonState, Mouse}; impl Mouse { pub fn move_to(absolute: bool, dx: i32, dy: i32) { + let width = unsafe { GetSystemMetrics(SM_CXVIRTUALSCREEN) }; + let height = unsafe { GetSystemMetrics(SM_CYVIRTUALSCREEN) }; + if width == 0 || height == 0 { + return; + } let pressed_left = Self::pressed(Button::Left); let pressed_right = Self::pressed(Button::Right); let pressed_middle = Self::pressed(Button::Middle); - let mut dw_flags = MOUSEEVENTF_MOVE | MOUSEEVENTF_VIRTUALDESK; if absolute { @@ -35,8 +40,12 @@ impl Mouse { type_: INPUT_MOUSE, u: unsafe { transmute(MOUSEINPUT { - dx, - dy, + dx: (dx - { GetSystemMetrics(SM_XVIRTUALSCREEN) }) * 65535 / { + GetSystemMetrics(SM_CXVIRTUALSCREEN) + }, + dy: (dy - { GetSystemMetrics(SM_YVIRTUALSCREEN) }) * 65535 / { + GetSystemMetrics(SM_CYVIRTUALSCREEN) + }, mouseData: 0, dwFlags: dw_flags, time: 0,