Link to home
Start Free TrialLog in
Avatar of kushcu
kushcu

asked on

keyboard buffering

I'm currently working on a simple 2D game, and almost everything's complete expect for one disturbing problem. I decided to use keyboard for controlling the human ship:

case WM_KEYDOWN:
..if (!keyBlock)
....poManager->ReceiveKeyPress(wParam);
....keyBlock = true;
..return 0;

what the poManager does is to simply call another class' member function to do keyboard processing. (a set of switch-case statements that test which key has been pressed. -like UP, DOWN arrows, etc..)
A timer assigns the false value to keyBlock every 50ms.

The problem is when I'm controlling the ship, say I press the left arrow key, and hold it down. And then, just as every computer gamer does, I wish to go diagonally (left and up), and press the up arrow key. Unfortunately no. I keep going only left.

Is there any clean way to do this.
(I don't use directx, native win32 api)

Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

the 'keyblock' variable just specifies that a key was (and/or still is) pressed. Any other keypresses are lost or ignored.
Perhaps you should keep a list of boolean 'keyblock' variables, one for each key, and then test only the keyblock variable associated with that key in the WM_KEYDOWN message.
ASKER CERTIFIED SOLUTION
Avatar of kamarey
kamarey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kushcu
kushcu

ASKER

I guess this stuff uses MFC, but anyway, the idea should solve the problem.
thanks.