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.22k stars 1.24k forks source link

locateAllOnScreen returns different coordinates than locateOnScreen for the same result, with multiple monitors. #722

Open gcfrxbots opened 2 years ago

gcfrxbots commented 2 years ago

When finding an image on my 1080p side monitor with a 1440p main monitor, pyautogui.locateOnScreen('img.png') returns the correct point of Point(x=-1257, y=619), which moveMouseToLocation is able to use.

However, when running a similar piece of code for position in pyautogui.locateAllOnScreen('img.png'): print(pyautogui.center(position))

it returns Point(x=663, y=619).

I noticed that if I move the image to the bottom of my 1920x1080 screen, it returns locateAllOnScreen returns Point(x=652, y=1339), which doesn't even exist on the screen that it is on.

Is there a workaround for this, or is this a bug? Thank you.

AaronKe11er commented 2 years ago

That will sometimes happen I believe it depends on the screen resolution and a few other factors. The issue is usually that it doubles the actually sizes so try dividing the points by 2 and that should fix it.