Closed zkghost closed 5 years ago
Mouse absolute positioning is like you did (old post mentioning this detail), see for example:
But I really never tried a monitor setup like yours, so at the moment, I can tell from experience the expected behavior.
Hmm, I see. I was actually playing around, I think I found out at least how to get the input coords to translate successfully into the absolute positioning space
transformation_math(desired_y_pixel) * (main_monitor_height / largest_monitor_height - 1)
So in my case, 1200
(from my main 1920x1200 monitor) / 2159
(from my 4K monitor).
It is sort of annoying though, because when I query the system for all the monitors and their bounding boxes, the pixels given are post DPI scaling, ie:
# left top right bottom
[-3840, 0, -2304, 864
The left/right coordinates are negative because they are left of my main monitor, but you'll notice it goes from 3840
to 2304
, instead of going from 3840
to 0
; that is due to the 250% scaling on that monitor.
Detecting the scaling is a little tricky (for example, I can't detect the scaling on the Y-axis in my scenario because my monitors are arranged horizontally), but I think I can do it.
Anyways, I'll go ahead and close this and leave this here for anyone else who hits a similar issue. Thanks for the response!
Context
I am writing a program to control mouse movement using your project (via autohotpy) and have run into some issues getting the mouse to go where I expect it.
The code to move a mouse in Autohotpy is as follows:
My monitor setup is something like this:
So a 4k monitor on the left, two 1920x1200 monitors on the right, and the middle monitor is the primary display.
I discovered that I can't just enter the
x
andy
values for a stroke directly to move the mouse to that pixel (ie: if callmoveMouseToPosition(500,500)
and then query the position of the mouse, it is actually somewhere else.This works on a single monitor setup, however. I am glad that works but would like my program to work regardless of user monitor setup.
I pieced together that the constant factor for mouse movement
65535.0
represents all pixels across a dimension (width/height). So when I want to move to say,x: 960 y: 0
(middle top of the primary monitor), what I have to do is:3840
(offset from the first 4k monitor) and5760
(3840 + the 1920 width of the primary monitor4800
0.625
40959.375
x * (65535/1920) = 40959.375
(x
times scaling factor over main monitor width = target proportion of 65535): 40959.375/(65535.0/1920) =1200
If I input
moveMouseToPosition(1200, 0)
, then it correctly places it at pixel 960 on the main monitor (in the middle of the 1920 pixel width).Problem
I've found I can't do the same in the Y axis. If I hop through the same gymnastics (though it is much easier because my monitors aren't stacked vertically), I should be able to do:
600
(middle of monitor along y-axis) =32767.5
(half of65535
) / (65535
/1200
(main monitor height))But inputting
moveMouseToPosition(0, 600)
doesn't place me in the middle of the main monitor, it places me at the bottom (x: 0, y: 1079
).The code I'm using to determine mouse location after I've moved it via the inception driver:
Here's the output of targeting different positions along the Y-axis in 120 pixel increments (1/10th of 1200), where I'm trying to do the same math above on the input to transform it into the proper value to be the right value in the output space:
You can see that the actual output mouse location is far off from the input pixel, and the ratio between the input value and output location differs for different inputs.
Just looking at the output, it looks like I could get the
y
value close to the intended value by multiplying the output by11/20
(55%). But then my project becomes very specialized for my scenario, which I'd rather avoid.I guess I could also do some calibrating by doing mouse movements and measuring the actual location the mouse ends up at, and fitting the coefficient that way, but that seems like a lot of unnecessary overhead.
Questions