With the below program, whenever I press the "a" key, the keypresses variable increments by 1. The problem is, if I don't immediately let go fo the key, the keypresses variable continues to increment by 1.
How can I get it to increment (and print) whenever I press the key, ignoring the hold aspect?
import keyboard
keypresses = 0
while True:
if keyboard.is_pressed("a"):
keypresses = keypresses +1
print(keypresses)
print("A Key Pressed")
break
I'd remove the
breakstatement. On the Python docs you can see thatbreakexits the innermostfor/whileloop, in your case the that loop would be the