I want to write a click speed tester which worked fine at first. Now I want you to have a certain time window in which you can click, then the final results are displayed. It will wait 2 seconds and then it should start all over again.
The problem is that when it starts over again, it also counts the clicks you performed in the 2-second pause. How can I fix this?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from time import sleep
import time
from pynput import mouse
import os
CPSL=0
CPSR=0
Time=5
mode="Time"#oneDrack, Time, Double
startTime=0
nowTime=0
CPSLT=0
CPSRT=0
double=0
buttosPressed=0
def on_click(x, y, button, pressed):
global CPSL, CPSR, mode, startTime, nowTime, double, Time, buttosPressed
if (str(button) == "Button.left" and pressed):
buttosPressed="CPSL"
CPSL+=1
if (str(button) == "Button.right" and pressed):
buttosPressed="CPSR"
CPSR+=1
if (mode == "Time"):
if (pressed):
if double==0:
print("start")
CPSR=0
CPSL=0
if (buttosPressed=="CPSL"): CPSL=1
else: CPSL=0
if (buttosPressed=="CPSR"): CPSR=1
else: CPSR=0
print(CPSL, end=" ")
print(CPSR)
double=1
startTime=time.time()
else:
nowTime=time.time()
difTime=nowTime - startTime
if (difTime < Time):
print(CPSL, end=" ")
print(CPSR)
else:
if (buttosPressed=="CPSL"): CPSL-=1
if (buttosPressed=="CPSR"): CPSR-=1
print("Finaly")
print(CPSL, end=" ")
print(CPSR)
sleep (2.5)
double=0
with mouse.Listener(
on_click=on_click
) as listener:
listener.join()