I'm very new to python and I have following problem. I'm trying to divide a variable (counta) by 3 and get the result every 10 seconds. At the same time I want to add 1 to the counter every time I press 'a'. The problem is that I'm using a method where I can only add 1 every 10 seconds. Please can you advise what could be changed so that I could add 1 whenever I like and i still get the current result (counta/3). Thank you in advance for your help. This is my code so far:
from pynput.keyboard import Listener
import sched, time
counta = 0
Timer = 0
def on_press(key):
if key.char == 'a':
#print("")
global counta
counta += 1
#print("Aktuell" + str(counta))
elif key.char == 'p':
print(int(counta/3))
elif key.char == 's':
Stand(counta, Timer)
else:
print("Falsche Taste!")
print("a = counta")
def Stand(counta, Timer):
while Timer < 10:
print(str(counta/3))
time.sleep(1)
Timer += 1
with Listener(on_press=on_press) as listener:
listener.join()
Listenerin differen way. Createlistener = Listener(on_press=on_press)beforewhileloop, and uselistener.join()afterwhileloop