954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Multiple keys pressed and PeekMessage.

Hello, everyone!

I'm using the Win32 API PeekMessage function to retrieve key stroke events. I have a problem: suppose that someone holds the A button. PeekMessage will return messages for the A press event. Now, while A is pressed, someone holds B. PeekMessage will return only the B press event message.

Do you know a way to retrieve A messages, even if B is holded by the player?

Thank you!

GDICommander
Posting Whiz in Training
211 posts since Jun 2008
Reputation Points: 72
Solved Threads: 26
 

Well you could keep an array of boolean values representing the keys on keyboard. Whenever you receive a WM_KEYDOWN or WM_KEYUP message you flag the corresponding key (wParam) as either true (pressed) or false (not pressed).

This way you should always be able to keep track of which keys are pressed, and which ones that aren't.

I hope this helps!
Emil Olofsson

emilo35
Junior Poster
103 posts since Feb 2010
Reputation Points: 14
Solved Threads: 12
 

I strongly suggest using DirectInput for this sort of keyboard handling, it vastly simplifies the handling of multiple keypresses and can be easily implemented using the message processing model you have mentioned below.
There are many examples on Microsoft's website on how to use DirectInput, in particular I recommend downloading the DirectX 9 SDK and checking out the samples included.

Hello, everyone!

I'm using the Win32 API PeekMessage function to retrieve key stroke events. I have a problem: suppose that someone holds the A button. PeekMessage will return messages for the A press event. Now, while A is pressed, someone holds B. PeekMessage will return only the B press event message.

Do you know a way to retrieve A messages, even if B is holded by the player?

Thank you!

Taurusk
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You