如何让pyautogui的点击在mac上工作? [英] How to get pyautogui's click working on mac?

查看:38
本文介绍了如何让pyautogui的点击在mac上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pyautogui 的点击方法的问题:我正在从 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()

操作系统: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)

这篇关于如何让pyautogui的点击在mac上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆