Skip to content Skip to sidebar Skip to footer

Ignore Keyboard Input In Python While Sleeping

I'm having a code with a loop asking for some input and then sleeps for some time. The purpose is to prevent for human errors, forcing the user to wait before entering the next inp

Solution 1:

Sorry for wrong answer that i have posted before(as i have deleted though), it is the human level problem that you are asking for.

The program thread is the only event that is put on to sleep, while the keyboard process is still running obviously it will record all the inputs and type after resuming from sleep.

This can't be achieved in this fashion


Solution 2:

This is an OS dependant issue, for windows i use this:

import msvcrt
import time

time.sleep(4)
while msvcrt.kbhit():
    flush = input()
entry = input("Press enter!")

it just catches all the inputs before asking user for a new input, hope it helps!


Post a Comment for "Ignore Keyboard Input In Python While Sleeping"