Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Listen For A Single Letter Input When The Terminal Is Open

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading