【发布时间】:2021-08-08 11:15:02
【问题描述】:
我想创建一个自动点击器,它会“记住”我的鼠标指针的当前位置,移动到桌面上的特定位置,执行双击,然后回到原来的位置,并且每隔 1 到 4 次随机执行一次秒。通过这种方式,我想在特定位置实现自动点击,并且或多或少能够使用鼠标浏览其他内容。
我想在另一个窗口中单击,它是一个程序,我在桌面的一半上保持打开状态,而在另一半上我想做其他事情。问题是自动点击器不会使程序成为活动窗口并且点击不起作用。
import pyautogui
import threading
import random
def makro():
z = random.randint(1,4) #timer set to random value between 1 and 4 seconds
(x, y) = pyautogui.position() #remember current position of mouse pointer
threading.Timer(z, makro).start()
pyautogui.doubleClick(1516, 141) #perform a double click in this location (this clicks do not make the window active and clicks do not work)
pyautogui.moveTo(x, y) #come back to original mouse pointer location
makro()
感谢您的帮助
【问题讨论】:
-
也许在另一个窗口上单击一下使其首先成为活动窗口?就像你自己做的那样,以防窗口没有激活......
标签: python automation