Home c++ getch () - waiting for keystrokes in C++

getch () – waiting for keystrokes in C++

Author

Date

Category

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 ()

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions