I want to create a python code where if I press the number 0, the number 0 gets returned as output. But when I use the keyboard.is_pressed() module it keeps spamming, I was wondering if it's possible to stop it without using time.sleep() or quit().
CODE:
import keyboard
while True:
if keyboard.is_pressed('0'):
print('0')
OUTPUT:
0
0
0
0
0
0
0...
You need to consider the state of the button, and print '0' only if the key is pressed at the moment.
The below code will print '0' only when it is pressed.