asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.15k stars 1.23k forks source link

Mac OS - Resolution problem / locateonscreen/get position #281

Open Ohmano1 opened 5 years ago

Ohmano1 commented 5 years ago

Hello,

I have a problem with locate onscreen function. I try to let my python script find a specific picture in the screen and then clicking on it. The script finds the specific picture, but it doesn't click right on it.

For example: The searched picture is at coords 40/255(that says the pyautogui.getposition). When I now try to use locate onscreen and click, it says me the picture is at 80/510. So it always double the coordinates.

I work on a Mac, the screen resolution is 2560x1600. But pyautogui.size says 1280x800, so again the half.

What can I do to fix this issue??

Edit: It seems like my resolution is 2560x1600. But due to retina its just 1280x800. I changed it manually to 2560x1600 and everything works good then. Is there any fix that python use the resolution which is currently used?

bjanzen commented 5 years ago

You are on a Retina display at 2x resolution and have to account for that. It’s been discussed.

Ohmano1 commented 5 years ago

Yes, I found that out too. But I don't know how to divide those coordinates by 2 to get the correct coordinates.

Ok I found a solution here https://github.com/asweigart/pyautogui/issues/33

BenRoe commented 4 years ago

The wrapper python-imagesearch solves this problem. Check out this lines. https://github.com/drov0/python-imagesearch/blob/88bf9eecb772ff5e657d4780d65cdff87cc5527d/imagesearch.py#L113-L127

CLOSE