Possible duplicate:Non-blocking getch (), ncurses
I am trying to make a Tetris game in a standard console. I need a non-blocking getch (), so blocks can fall without pressing any key. It would be nice to have a function that returns -1 if no key is pressed, otherwise key code.
I would be glad if someone could give me a hint or some links.
This operating system is specific, but your library probably has a kbhit () function or similar that will do this
This is exactly what you wanted:
int getch_noblock() { if (_kbhit()) return _getch(); else return -1; }
Basically kbhit(), a determination is made whether a key is pressed.
kbhit()
Windows Microsoft Visual ++.