pythonmathsleeppynputcps

How do I execute a function X times per second?


I am writing an auto clicker and want to have the delay as a CPS (clicks per second) so, how would I work out the delay from the CPS value in python?

I have tried googling but only found CPS testers, no actual code

Here is a snippet of code:

def clickerstart():  #this functions activates when you press the "start" button in the autocklicker menu  ¦
    if clickerlmb == 1:
        mouse.press(Button.left)
        time.sleep(delay) # "delay" is the time to sleep, found from the CPS
        mouse.release(Button.left)

Solution

  • period = 1 / frequency

    You're converting clicks per second into seconds per click. In terms of your likely variables:

    delay = 1 / cps