Usually getch ()
waiting for the user to press the key, and if it does not press the key, the function will never end.
How to make the waiting for pressing in, say, half a second, after which the function is completed, returning, for example, 0x00
?
Answer 1, Authority 100%
Judging by Getch
, you write in something old and you are available Kbhit
– Use it to check if the key is pressed.
If you need to modern, then use WinAPI function peekconsoleinput
.
Answer 2
To organize a delay, you can use While (! kbhit ()) {…}
And instead of just getch () use better option _Getch ()