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!

Recommended Answers

All 2 Replies

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.