View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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

4 replies to this topic

### #1YodaTheCoder  Members

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

### #2Oluseyi  Members

Posted 12 October 2001 - 08:38 PM

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

### #3Anonymous Poster_Anonymous Poster_*  Guests

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 keyif (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 keyif (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

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

### #5playmesumch00ns  Members

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.