Listen For A Single Letter Input When The Terminal Is Open
Question:
I want to make a project which is a bit like a quiz. I want to make it so that instead of typing Y the pressing Enter, I want it to be you press the Y key on your keyboard and wait 5 seconds before the terminal automatically accepts it.
Answers:
This sounds like you want to read keyboard input.
I would check out this page: https://www.delftstack.com/howto/python/python-detect-keypress/
There is a module to detect keyboard input. They also post a nice example:
import keyboard
while True:
if keyboard.read_key() == "p":
print("You pressed p")
break
while True:
if keyboard.is_pressed("q"):
print("You pressed q")
break
keyboard.on_press_key("r", lambda _:print("You pressed r"))
I want to make a project which is a bit like a quiz. I want to make it so that instead of typing Y the pressing Enter, I want it to be you press the Y key on your keyboard and wait 5 seconds before the terminal automatically accepts it.
This sounds like you want to read keyboard input.
I would check out this page: https://www.delftstack.com/howto/python/python-detect-keypress/
There is a module to detect keyboard input. They also post a nice example:
import keyboard
while True:
if keyboard.read_key() == "p":
print("You pressed p")
break
while True:
if keyboard.is_pressed("q"):
print("You pressed q")
break
keyboard.on_press_key("r", lambda _:print("You pressed r"))