Easy way to work with the keyboard?

I am making a simple program using graphical mode in C ++, I am having problems with input. I just need to check the keyboard, and if any key is pressed, save the key value for the variable, the problem getch()is that it waits until any key is pressed, and I need the program to continue if the user does not enter input. I have done research and it seems like there are hundreds of ways to do this. which one is the easiest?

Example: a cycle starts, the program checks if there was any input and stores it, the program works with this input, and then discards it to start the cycle again. This works great with getch(), right? Well, I want the loop to keep going if this time the key is not pressed. The input type view is the default, so the process does not stop.

(what I really liked is equivalent getch()to not expecting user input).

Windows, Code :: Blocks IDE, GCC Compiler

Yes, kbhit seems to work as expected, thanks!

+3
source share
1 answer

Use int _kbhit( void );: this is a non-blocking call getch()(only works on Windows). It is also included inconio.h

Doc : http://msdn.microsoft.com/en-US/en-en/library/58w7c94c.aspx

( * nix: http://cboard.cprogramming.com/c-programming/63166-kbhit-linux.html)

0

All Articles