我对Python来说还很陌生,但是尽管有使用其他语言的经验,但它的语法似乎使我不胜其烦。
在下面的代码中,对于for循环中对autoclick
的调用,我有一个未解决的引用,但我不确定为什么。我认为这可能与我的参数有关,因为当我调用single_click()
和double_click()
时没有错误。
minDelayMs = int(input("Minimum delay between clicks (ms)?"))
maxDelayMs = int(input("Maximum delay between clicks (ms)?"))
clickType = input("1 or 2 clicks?")
numClicks = input("Number of clicks?")
minDelaySec = minDelayMs / 1000
maxDelaySec = maxDelayMs / 1000
print("Min delay (seconds): " + str(minDelaySec))
print("Max delay (seconds): " + str(maxDelaySec))
totalTime = 0
totalClicks = 0
print("10 second delay until start...")
time.sleep(10)
print("Starting")
for x in range(int(numClicks)):
auto_click(minDelayMs, minDelayMs, clickType)
def auto_click(minDelayMs, maxDelayMs, clickType):
global totalTime
global totalClicks
#get next delay in ms
delay = random.randint(minDelayMs, maxDelayMs)
totalTime = totalTime + delay
print("Next delay in ms: " + str(delay))
# sleep for the delay in sec
time.sleep(delay/1000)
if(clickType == 1):
single_click()
if(clickType == 2):
double_click()
totalClicks += 1
clicksRemaining = int(numClicks) - totalClicks
print("Clicks remaining: " + str(clicksRemaining) + "\n")
return
def single_click():
mouse.press(Button.left)
time.sleep(0.5)
mouse.release(Button.left)
time.sleep(0.5)
print("Click cycle")
return
def double_click():
mouse.press(Button.left)
time.sleep(0.5)
mouse.release(Button.left)
print("Click cycle")
time.sleep(0.5)
mouse.press(Button.left)
time.sleep(0.5)
mouse.release(Button.left)
print("Click cycle")
return
答案 0 :(得分:0)
您的函数应在使用前声明。然后,您可以在全局for
循环中使用它,这意味着立即执行。