Closed HeisenBug1 closed 3 years ago
On my screens, there is a factor 2 on x and y returned by locateCenterOnScreen
On my screens, there is a factor 2 on x and y returned by locateCenterOnScreen
that's correct. the coordinates are off by a factor of 2. so a workaround is to use locateCenterOnScreen()
and divide the coordinates by 2 before using them.
I will reopen that because it still needs a fix even if a workaround is available
The factor 2 is devicePixelRatio.
pixelRatio = pyautogui.screenshot().size[0]/pyautogui.size().width
@hangj thanks... instead of a fixed factor 2, a pixel ratio would be better..
This is an issue with Windows also, with its scaling options.
With 125% scaling, which is the default and recommended on this machine, the coordinates of locateCenterOnScreen()
are 1.25 times what they should be.
very interesting!
The factor 2 is devicePixelRatio.
pixelRatio = pyautogui.screenshot().size[0]/pyautogui.size().width
can u explain more about it?
The factor 2 is devicePixelRatio.
pixelRatio = pyautogui.screenshot().size[0]/pyautogui.size().width
can u explain more about it?
Sometimes the screen is scaled up/down, either by default, or you can do it manually to make things bigger/smaller. This causes the LocateCenterOnScreen() or any other similar functions to be off by the factor the screen was scaled to. In my case it was a factor of 2. So instead if we use this formula to get a device pixel ratio, it'll work for every scaled screen sizes..
locateOnScreen()
works perfectly on Ubuntu Linux but on MacOS it always adds a varying offset. As X increases, the coordinates returned bylocateOnScreen()
increases by a certain ratio, similar for Y but increases slightly less.Doesn't matter how many desktop/workspaces I have active, the result is the same.