mouse-rs icon indicating copy to clipboard operation
mouse-rs copied to clipboard

Windows scaling also scales mouse-rs locations

Open popcar2 opened this issue 2 years ago • 1 comments

I was going mad at how the pointer location was inaccurate before I figured this out: windows scaling options also scales the mouse location when using move_to(). image Despite my monitor being 1920x1080, move_to() is also scaled by 125%, meaning I reach the bottom right corner of the screen at move_to(1536, 864)

I realize this project hasn't been updated in a year but this is probably unintentional and I hope someone can get around to fixing it.

Worth noting it's not a huge deal if you know the current scale, but the problem is if I'm giving the program to someone else.

let mouse = Mouse::new();
let loc_x = (f64::from(INTENDED_X) / 1.25).floor() as i32; // Assuming you're at 125% scale. 
let loc_y = (f64::from(INTENDED_Y) / 1.25).floor() as i32; // Not 100% accurate because it has to be i32, so I have to floor or get average.
mouse.move_to(loc_x, loc_y);

popcar2 avatar May 22 '22 17:05 popcar2

https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getscalefactorformonitor is possibly a solution, adding a loc * scalefactor could do the job

AltF02 avatar May 23 '22 00:05 AltF02