I need to stop a program when a keyboard key q is pressed. How can I achieve that in the below code? How can I ignore time.sleep
& detect a keypress & exit the program by printing something? Currently, the keypress gets detected only after 10 seconds. Suppose I am pressing q after 3 seconds the program doesn't exit.
import sys
import time
import keyboard
def hd():
print("Hi")
time.sleep(10)
if keyboard.is_pressed("q"):
print(keyboard.is_pressed("q"))
sys.exit()
while True:
hd()