This commit is contained in:
crusader 2020-11-25 13:51:11 +09:00
parent 05aa626948
commit 88c8e0354a

View File

@ -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,