Archived

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

Key repeat?

This topic is 5936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Curious as to how I may end this bloody (that''s with some British emphasism) key thing.. You know when you push a character, it inputs it, waits a little, then starts an input loop? Well, I''ve been trying to get rid of that while I use the ''a'' and ''d'' key''s to move my figure around the screen. Any functions? ~Jesse "Sleep is to me as honest is to lawyer."

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here''s how I do it without DirectInput. Yes, DI is better to use but I haven''t learned it yet.


//////////////////////////////////////////////////
// Global Variables
//////////////////////////////////////////////////
BOOL keyPressed[256];
BOOL keyDown[256];

...
LRESULT CALLBACK WndProc(...)
{
...
case WM_KEYDOWN:
keyPressed[wParam] = TRUE;
return 0;
break;

case WM_KEYUP:
keyPressed[wParam] = FALSE;
return 0;
break;
...
}


And wherever you want to test your keys:


// for a non repeating key
if (keyPressed[''A''] && !keyDown[''A''])
{
keyDown[''A''] = TRUE;

// do stuff here (will not repeat until key is let go of)
}
else if (!keyPressed[''A''] && keyDown[''A''])
keyDown[''A''] = FALSE;

// for a repeating key
if (keyPressed[''D''])
{
// do stuff here (will repeat while key is down)
}


Yes, this may not be the best way but it works very well for me without having to learn DI. =) Hope this is of some help and if anyone sees and problems with the way I do it, let me know.

- Mike

Share this post


Link to post
Share on other sites
another way to do it (again without DirectInput) is to use the GetAsyncKeyState(...) function.

This will tell you whether a key is down or up at the moment you call it... so just stick this call in your game loop, or in a timer function, or wherever you feel like checking your keys... i don''t care

Share this post


Link to post
Share on other sites
Just use DirectInput. The SDK''s help files tell you everything you need to know, and once you''ve got round the pain of setting up objects etc it''s very easy to use =]

Share this post


Link to post
Share on other sites