Jump to content

  • Log In with Google      Sign In   
  • Create Account

Key repeat?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 YodaTheCoder   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 October 2001 - 08:18 PM

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."

Sponsor:

#2 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 12 October 2001 - 08:38 PM

That''s what DirectInput is for, largely. You can also look into the WM_KEYDOWN window message.

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 15 October 2001 - 05:58 AM

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

#4 Bad Monkey   Members   -  Reputation: 145

Like
Likes
Like

Posted 15 October 2001 - 07:37 PM

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

#5 playmesumch00ns   Members   -  Reputation: 190

Like
Likes
Like

Posted 17 October 2001 - 01:10 AM

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 =]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS