Im writing keyboard navigation to the console program, and I have issue with combine GetAsyncKeyState() with _getch().
Usually I put GetAsyncKeyState() in to while loop, because of that program can listen keyboard even in the background. After the user presses that specify key, program sometimes goes to _getch(), to get some more information from the user.(I uses _getch() because its get keys only when the console is in foreground.)
Here comes the problem. Its seams that program absorb some amount of pressed keys in the GetAsyncKeyState() loop, and when I decide to press that specify key to unlock the rest of the program, next code _getch() function just freak out and read those keys I pressed before.
Is there any way to flush that 'bufor' or I need to use something different than _getch()? : p
http://sscce.org/
It's normally better to post a Short, Self Contained, Compilable, Example.
Than describe in vague, possibly inaccurately, what you're doing.
It also means we could take your code, try it, make a necessary correction or two and reply back.
As already stated, give some code, but with that said....
These two functions are quite different. _getch pulls information from a queue of keystrokes in the order they happen, which also means you don't necessarily get the key currently being held down when called. GetAsyncKeyState hints in it's very name that this function reads the current state of the keyboard, without much regard to keystrokes missed earlier.
This means you can get a key from _getch that does not accurately pair with information from GetAsyncKeyState when keyboard actions are happening fast enough that more keys are waiting behind the first obtained. Put another way, GetAsyncKeyState information may apply to a value returned from _getch much later than the current call to _getch.
You may benefit from researching GetKeyboardState, but like others have stated without the context of code which gives me some hint as to what you're actually doing, I can't say that's the best option.