Search code examples
pythonclickpywin32

python autoclicker - random time interval


I have this autoclicker and it works so far.

Most autoclickers have a set time, click every second, every 2 seconds, etc.

I need this program to generate a random time (preferably between .75 and 1.25 seconds).

Anyone have any ideas as to how I could do this?

So my goal is to create an autoclicker that clicks in random time intervals instead of after a set amount of time.

Below is the code I have so far.

import win32api, win32con
import time

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)

x = 0

while (x < 5):
    a, b = win32api.GetCursorPos()
    click(a, b)
    x = x + 1

Solution

  • In the while loop add the line time.sleep(0.75 + 0.5*random.random()).

    And add import random at the top.