如何在Mac上使pyautogui的点击工作? [英] How to get pyautogui's click working on mac?
问题描述
pyautogui的click方法的问题: 我正在从Spyder运行脚本,如果我在Spyder的窗口上单击任何内容,则单击可以正常工作.
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.
如果我执行脚本打开Outlook,然后单击任何东西,则单击不会发生.尽管我能够正确使用"moveTo"功能.
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
OS : mac os high sierra
注意: 为了到达任何定位的图像,我必须做坐标/2,因为它是Retina 2x显示器.
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.
推荐答案
对于在Mac上可能会遇到相同问题的任何人,我都可以通过使用使用Pynput库的变通办法来使其工作.
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.
代码:
import pyautogui
from pynput.mouse import Button, Controller
mouse = Controller()
pyautogui.moveTo(x,y)
mouse.click(Button.left)
这篇关于如何在Mac上使pyautogui的点击工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!