如何每秒执行一次函数X次?

问题描述

我正在编写一个自动答题器,并希望将延迟作为cps(每秒的点击数),那么,如何从python中的cps值计算出延迟?

我尝试使用谷歌搜索,但只找到了cps测试人员,没有实际代码

这是一段代码

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)

解决方法

期间= 1 /频率

您正在将每秒的点击次数转换为每次点击的秒数。根据您可能的变量:

delay = 1 / cps