[Python] How to hold an input open for a specific length of time

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    A project I am working on needs to automatically accept an input after 5 seconds. the idea is that they have 5 seconds to enter as many particular characters as possible.

    I've found plenty of examples of inputs with time limits (like inputimeout), on this website and others, but none of them have what I'm looking for.

    All the programs I've found do hold the input open for the correct amount of time, but once that limit is hit, it discards whatever the user has typed in so far.

    (after running pip install inputimeout)

    from inputimeout import inputimeout, TimeoutOccurred
    try:
    something = inputimeout(prompt='>>', timeout=5)
    except TimeoutOccurred:
    something = 'something'
    print(something)


    I need the program to keep whatever the user has typed in and use that as the accepted input - the player shouldn't be pressing the enter key at all.

    can anyone help?

    Continue reading...

Compartilhe esta Página