我正在尝试使用 Python 中的 PyAutoGUI 将发送表情符号的过程自动化,作为一个有趣的项目。我的代码旨在单击屏幕上的特定坐标来选择表情符号,然后按“Enter”键发送它们。但是,我在循环运行多次代码时遇到了问题。
问题: 当我将限制设置为(例如)3 并执行代码时,第一次迭代工作得很好,但后续迭代无法单击所需的坐标。鼠标移动到指定坐标但不执行点击动作。
代码:
import pyautogui as pt
import time
pt.FAILSAFE = True
limit = int(input("Number of actions: "))
time.sleep(5)
def send_emoji():
i = 0
while i < limit:
pt.click(x=459, y=699, clicks=1, interval=1, button='left')
pt.click(x=258, y=460, clicks=1, interval=1, button='left')
time.sleep(1)
pt.press('enter')
i += 1
try:
send_emoji()
except pt.FailSafeException:
print("Execution stopped due to failsafe (moved mouse to top-left corner).")