Checking for "key pressed" in C++?

K

Koen

Hi!

What is the best way to check whether a key is pressed without blocking
in C++?

I know I can use cin.get(c) to get a character from standard input, but
this blocks.

And I know _kbhit() exists in MSVC++, but that's in <conio.h> and
probably not standard, is it?

I need a way to say:
1. do something
2. check if a key was pressed
3. if no key was pressed, go to 1.
4. if a key WAS pressed, continue with 5.
5. the rest of the program

Thanks in advance for any hints!

Koen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top