简体   繁体   中英

How to get pyautogui's click/moveTo working on mac?

** Python pyautogui's click and moveTo functions not working ! **

I am running these codes from VSCode.

Import pyautogui
from time import sleep
sleep(1)
print(pyautogui.position())
sleep(1)
pyautogui.moveTo(0,0,2) # moves mouse to (0,0) over 2 seconds
pyautogui.click(0, 0)
sleep(1)
print(pyautogui.position())
Output:
Point(x=1084, y=167)
Point(x=1084, y=167)

Did not touch the mouse while the program is running.

The position of the mouse cursor was printed out correctly, but the mouse cursor do not move to the new location (0,0) but stays where it was.

Any help will be greatly appreciated.

Python 3.8.8 installed with pyobjc and pyobjc-core. OS : macOS Big Sur VSCode 1.58

You can just use a separate library called pynput . You can install it with pip3 install pynput . I was facing the same issue the other day and I used pynput to fix it. Their documentation is pretty good as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM