Archived

This topic is now archived and is closed to further replies.

Bagpuss

can anyone explain this ? (WM_KEYDOWN Problem)

Recommended Posts

In my code (MS Vis Studio 6, Win 98) I have some basic code to detect when the left or right arrow is pressed. When the left arrow is pressed, I see my shape move across the screen 10 pixels at a time (what I expect) When the right arrow is pressed, it leaps across the screen in one go. I assume that this is due to a keyboard repeat, but both keys are handled the same, and the move algorithms are almost identical (1 is x += 10 and 1 is x-= 10) A second issue is I am trying to prevent the keyboard repeat by doing the following in my wndproc case WK_KEYDOWN: if (!(lParam & 0x40000000)) { blKeys[wParam] = TRUE; } else { blKeys[wParam] = FALSE; } Yet this doesn''t actually work for the VM_ keys. Any ideas why ? TIA, Bp. So this should only set the Array to True when the key is pressed for the first time, else reset it.

Share this post


Link to post
Share on other sites
You won''t get a KEYDOWN message for a key when that key is **RELEASED**

i.e.:
blKeys[wParam] = FALSE;

only happens when you press a DIFFERENT key DOWN.


Hint: WM_KEYUP


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Thats why I am testing to see if the key was down last time (0x4000000).
I also have the reset code in WM_KEYUP.

I just wondered why on the left key it seems to repeat slowly, and on the right key it repeats fast.

Share this post


Link to post
Share on other sites
Since you are specifically looking for the state of two keys, why not simply query the state of those keys specifically. You avoid the whole key repeat issue that way.

Share this post


Link to post
Share on other sites
all you need to do is test which key is being pressed via GetAsyncKeyState().

Example:
if (GetAsyncKeyState (VK_LEFT) & 0x80)
{
   // move object left
}
if (GetAsyncKeyState (VK_RIGHT) & 0x80)
{
   // move object right
}

-noix-


In this world gone mad, we won''t spank the monkey; the monkey will spank us.

Share this post


Link to post
Share on other sites