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

SetCursorPos bug in Windows affecting pyautogui #679

Open selomkofori opened 2 years ago

selomkofori commented 2 years ago

SetCursorPos API has a bug relating to having multiple monitors with different dimensions.

If the cursor is in secondary Monitor B and you move it to Monitor A, the X position MAY be bounded incorrectly.

Issue is explained here https://stackoverflow.com/questions/65519784/why-does-setcursorpos-reset-the-cursor-position-to-the-left-hand-side-of-the-dis

The workaround is to call SetCursorPos twice. Posting this as an issue because it may not be obvious why the bug is happening in pyautogui.

The reason I propose it be fixed in pyautogui is so that it works consistently in the api and across platforms.

InfamousPlatypus commented 2 years ago

According to https://github.com/asweigart/pyautogui#keyboard-and-mouse-control Currently, PyAutoGUI only works on the primary monitor. PyAutoGUI isn't reliable for the screen of a second monitor (the mouse functions may or may not work on multi-monitor setups depending on your operating system and version).

I also assume this could cause issues with the failsafe. https://pyautogui.readthedocs.io/en/latest/#fail-safes

It is also in the roadmap https://pyautogui.readthedocs.io/en/latest/roadmap.html I haven't done anything here before, so I don't have any say anywhere, but I'm sure assistance with that issue would be appreciated.

See also, #192