How to get pyautogui's click working on mac?

2020-04-21 06:43发布

pyautogui's click method's issue: I am running the script from Spyder, if I click anything on Spyder's window the click works fine.

If I execute a script to open Outlook, then click on anything, the click does not happen. Although I am able to use the "moveTo" functionality properly.

Things I have tried as suggested by doing google search:

pyautogui.click()
pyautogui.click()

OS : mac os high sierra

Note: In order to reach any located image I have to do coordinates/2, as it is a Retina 2x display.

Any workaround or any help will be greatly appreciated.

3条回答
仙女界的扛把子
2楼-- · 2020-04-21 06:46

I was also facing same issue, Here is what I tried :

Just add one more line pyautogui.dragTo() to focus on that particular selected area:

pyautogui.moveTo(990,28)
pyautogui.dragTo() 
pyautogui.click()
查看更多
劫难
3楼-- · 2020-04-21 07:06

OS X Mojave, the following works for me:

    pyautogui.moveTo(pos)
    pyautogui.dragTo(button='left')

pyautogui.click() throws an attribute error but pyautogui.dragTo() works instead.

查看更多
我只想做你的唯一
4楼-- · 2020-04-21 07:12

To anyone who might stumble into the same issue on a Mac, I was able to get it working by using a workaround that is using the pynput library.

Code:

import pyautogui
from pynput.mouse import Button, Controller

mouse = Controller()
pyautogui.moveTo(x,y)
mouse.click(Button.left)
查看更多
登录 后发表回答