I want to count the number of 5s the user can input in 5 seconds. The prompt must be interrupted after 5 seconds. Here, the user will not have a chance to press the Enter key to close the prompt. Is there any way to count the number of 5s the user entered without actually the enter key being pressed?
Asked
Active
Viewed 95 times
1 Answers
0
The input()
function requires you to press enter to confirm the input, so that wouldn't work for you.
If you're using Windows, you could try the msvcrt
module, as highlighted in
this question's answers.
The general idea would be to loop for five seconds calling the getch()
function repeatedly.
If not on Windows, there were some other answers with cross-platform solutions, such as the curses
package.

Gabriel Jablonski
- 854
- 1
- 6
- 17
-
Can you please explain what msvcrt.getwche() does? – R06 Nov 19 '19 at 03:05
-
msvcrt.getch() runs infinitely and does not yield any result. Why? – R06 Nov 19 '19 at 04:36