如何使用 pyautogui 增加每秒的点击次数?

How to increase number of clicks per second with pyautogui?

我正在开发一个用于定时鼠标点击游戏的机器人。我正在使用 pyautogui。目标是在一分钟内点击按钮的次数最多。我的代码是:

import pyautogui, time
time.sleep(5)
while True:
    pyautogui.click()

无限循环不是问题,因为 FAILSAFE 会防止任何负面后果(pyautogui.FAILSAFE() 默认设置为 True)。本质上的缺点是,pyautogui 每秒最多只能达到 10 次点击。有人知道我是否可以增加每秒的点击次数吗?如果是,怎么办?非常感谢您的建议!

您可以设置pyautogui.PAUSE来控制动作之间延迟的持续时间。默认情况下,它设置为 0.1 sec,这就是您每秒最多获得 10 次点击的原因。

pyautogui.PAUSE = 0.01

例如,如果您的硬件支持,将减少延迟以允许每秒 100 次点击。 从doc中,您可以阅读到以下内容:

You can add delays after all of PyAutoGUI’s functions by setting the pyautogui.PAUSE variable to a float or integer value of the number of seconds to pause. By default, the pause is set to 0.1 seconds.