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

Started by
1 comment, last by nerd_boy 19 years, 9 months ago
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
Advertisement
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.
www.tmreality.com
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.

This topic is closed to new replies.

Advertisement