how to shut down keyboard input buffer to directly react my key strike

Jun 6, 2014 at 12:59pm
I am trying to write a game which need to control the action.
It is obviously bad to press enter key each time.

Because game needs infinit loop, so the waiting me press enter key each loop would stop the loop.
I need a way to check if there is input, a way to sidestep the cin buffer, which requires me strike enter key, a way to shut down the input and reopen the input.

would anyone be kind to show me the way.
Thanks so much!
Jun 6, 2014 at 2:40pm
You should not use cin then.
If you are on linux, use NCurses
If you are on Windows and do not use any libraries use WinAPI function GetAsyncKeyState or install hook to catch events: http://stackoverflow.com/questions/2067893/c-console-keyboard-events

Also you can use kbhit() function from <conio.h> header.
Jun 8, 2014 at 9:21am
thanks.
Topic archived. No new replies allowed.