pynput icon indicating copy to clipboard operation
pynput copied to clipboard

Coordinate system for multi-screen / multi-monitor setup not well defined

Open JayFoxRox opened this issue 3 years ago • 3 comments

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):

pynput-screeninfo

There must be a way for pynput to respect this case / provide information about display indices or the coordinate system used to find displays.

JayFoxRox avatar Jan 30 '21 11:01 JayFoxRox

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.

moses-palmer avatar Jan 31 '21 19:01 moses-palmer

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

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

link89 avatar Nov 18 '21 03:11 link89

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.

link89 avatar Nov 18 '21 06:11 link89