I want to take a timed input. If the user doesn't give the input under a limited amount of seconds, the program moves on. So, I learned about inputimeout() but even when I am giving the input within the time limit, it just waits for the timeout. (Also I am not able to solve the problem from other similar questions and that is why I decided to mention this problem)
from inputimeout import inputimeout, TimeoutOccurred
try:
something = inputimeout(prompt = 'Enter: ', timeout=5)
except TimeoutOccurred:
print('Time Over')
Output for the above code:
Enter: e
Time Over
Process finished with exit code 0
Even if I give the input within the time limit, it shows Time Over. Can anyone please help me out?
Keeping it simple, it is a module that reads input from the user, but with a twist, it has a timeout placed by the developer, if the program doesn't detect the information from the user, it skips the input. A simple way to use it would be:
timer = 2
var = inputtimeout(prompt='Enter: ', timeout=timer)
That would give the user 2 seconds to type, you can also increment with a trycatch block to give a message to the user in case of a timeout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With