我想创建一个非常简单的自动点击器,它将使用鼠标的位置,并在该位置单击,只要“ active”为true且以“ input”的速度(每秒点击数)

我已经看到了这段代码,但是它不符合我的需求

import win32api, win32con
def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
click(10,10)


我希望代码看起来像这样,

import library

input = 5 ## in clicks per second

if (some key) is held:
    active = True

if (some key) is released:
    active = False


while active:
     *gets position of mouse*
     *clicks at that position at input's speed (5)


如果可以选择在屏幕的正中央单击,这也很好。

最佳答案

尝试使用pyautogui。我已经在几个项目中使用了它。它具有功能强大,编码少。例如,如果您想单击屏幕中间,只需执行以下操作:

import pyautogui
width, height = pyautogui.size()
pyautogui.click(width/2, height/2)


在您的情况下,您可以使用时间模块来同步操作。

这是cheat sheet of pyautogui

10-07 13:36
查看更多