Checking the keyboard buffer

I need to write a routine that will do the following:

DO

   Check if keyboard buffer is empty

LOOP UNTIL Keyboard buffer is empty

So basically I need know how I can check the status of the keyboard buffer to determine if its empty or not.

What functions would I need to achieve this? I'm currently using Visual C++ 6.
LVL 10
Jason EvansSenior Software DeveloperAsked:
Who is Participating?
 
NickRepinConnect With a Mentor Commented:
It depends on you exactly want to do.
Do you need to check the buffer for your application only or for the whole system?

For your app only:

MSG m;
while(GetMessage(&m,0,WM_KEYFIRST,WM_KEYLAST)) {
   // Keystroke is available.
}
0
 
NickRepinCommented:
You can also use PeekMessage, GetKeyboardState, GetAsyncKeyState, GetKeyState
0
 
NickRepinCommented:
To check if key is *pressed* w/o waiting,

MSG m;
if(PeekMessage(&m,0,WM_KEYDOWN,WM_KEYDOWN,PM_NOREMOVE)) {
// Key is pressed

// To remove event
PeekMessage(&m,0,WM_KEYDOWN,WM_KEYDOWN,PM_REMOVE);
}
0
All Courses

From novice to tech pro — start learning today.