pynput
pynput copied to clipboard
Coordinate system for multi-screen / multi-monitor setup not well defined
I was trying to use pynput to set the mouse-coordinates on macOS. However, the coordinate system on the multi-monitor setup wasn't clear to me (i.e. the image is split across different displays). I also tried using pynput together with https://github.com/rr-/screeninfo, but it appears to use a different coordinate system.
(0,0) was the top left corner of the primary display in pynput, but it was the top left corner of the secondary display in pynput. I'm not at the problematic machine right now, but I believe what pynput recognized as (0,0) was something like ((2560-1680)/2, 1050) or even (-(2560-1680)/2, 1050) in screeninfo.
The setup (and results, as far as I remember them) was similar to this (also note DPI difference, leading to higher-res display having a smaller size):
There must be a way for pynput to respect this case / provide information about display indices or the coordinate system used to find displays.
Thank you for your report.
pynput does not perform any transformation of the input events received from the operating system on macOS, but your observations indicate that might be necessary.
It has something to do with the arrangement of the display.
Display 1 (primary)
pynput
: left, top = 0,0
screeninfo
: left, top = 0,0
Display 2
pynput
: left, top = -260,-1080
screeninfo
: left, top = -260,900
I think the one use by pynput
is correct, it respect the coordination by arrangement, the problem should be screeninfo
's
![Built-in_Retina_Display](https://user-images.githubusercontent.com/3314130/142344048-5040d99c-101b-47f6-8cc1-88ba6b3f2248.png)
@moses-palmer I was wondering is it possible for pynput
to provide API to get the (left, top, right, bottom)
parameter by display? e.g.
(left, top, right, bottom) = pynput.monitors[0]
(left, top, right, bottom) = pynput.monitors[1]
Or else we have to calibrate it for every computer with different configuration.
It works fine with mss
import mss
with mss.mss() as sct:
print(sct.monitors[1])
print(sct.monitors[2])
Output:
{'left': 0, 'top': 0, 'width': 1440, 'height': 900}
{'left': -260, 'top': -1080, 'width': 1920, 'height': 1080}
Just comment it here in case someone else need it.