question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

macOS - `locateOnScreen()` coordinates are off by a factor of 2

See original GitHub issue

locateOnScreen() works perfectly on Ubuntu Linux but on MacOS it always adds a varying offset. As X increases, the coordinates returned by locateOnScreen() 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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
hangjcommented, Jul 8, 2021

The factor 2 is devicePixelRatio.
pixelRatio = pyautogui.screenshot().size[0]/pyautogui.size().width

0reactions
chrischmacommented, Sep 24, 2022

very interesting!

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyAutoGUI locate command returning incorrect coordinates ...
I am trying to use pyautogui. locateCenterOnScreen() to find the exact point of an image on a screen, but whenever the coordinates are...
Read more >
PyAutoGUI Documentation - Read the Docs
The screen resolution size is returned by the size() function as a tuple of two integers. The current X and Y coordinates of...
Read more >
Screenshot Functions - PyAutoGUI documentation
The Locate Functions¶ · locateOnScreen(image, grayscale=False) - Returns (left, top, width, height) coordinate of first found instance of the image on the screen ......
Read more >
screenshot your return value will be different from the one ...
If the image is even a pixel off,locateOnScreen()will returnNone.If the image can be found in several places on the screen,locateAllOnScreen()willreturn ...
Read more >
How to fix Python 3 PyAutoGUI screenshot error? (macOS)
locateOnScreen('button.png') pyautogui.pixelMatchesColor(x, y, (r, g, b)) im = pyautogui.screenshot(). The error I get is: screencapture: cannot write file ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found