Sign in to follow this  
MartinNg

How to clear those queued keyboard messages before entering game loop?

Recommended Posts

hi, first,thanks you all for spending valuable time to look at my question. my question is how to discard those queued window keyboard messages before entering main game loop? i mean, while my game is busy loading, the player keep pressing some keys that used in game. once finish loading and enter the game loop, how i know those key message in msg queue are pressed before main game loop start, and how to discard them? any easy API like ClearKeyboardMessage()? :P sorry because my english is poor. i hope you all understand what i am asking. thanks Martin

Share this post


Link to post
Share on other sites
Just add 'null' message loop directly in the code in the place that you want to clear message queue in:


while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}


it's also useful trick if you are loading level it takes for example 30 secs and you want your window to respond to messages.

Share this post


Link to post
Share on other sites
Another way is to just read the input after loading, but before continuing(sp?) in the game loop. Then you can use memset() on the array holding the keyboard data to set it to 0. This is useful if you are using an API, such as DirectX.

There is a way to erase the entire keyboard information, using fflush(stdin), but that was for DOS/console programming, and I am not sure if it would work with windows/APIs. I would consider looking fflush() up on google for your specific needs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this