#### Archived

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

# Getting Keystrokes at 30 fps

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

## Recommended Posts

Im making the menu for a game that''s controlled by the keyboard w/ DInput. The up/down arrows select the item and then you press enter to choose it. However the game is running at about 30 fps so when someone press the up key it goes up a few items. I tried to fix this by having an int that is set to 0. Then when the key is pressed the int is increased by one and if it is above 4, a diffrent item is selected. This works ok but is still a little jerky. for example, if the person let go of the key when the int is a 4, the next time he presses the key it will jump to the next item very quickly. I hope this makes some sort of sense. Does anyone have any other ideas how to implement this? thanks

##### Share on other sites
First, your menu should be outside of your main rendering loop.

Secondly, you can fix your problem by testing for the key down and key up sequences. Initially the key will be up, then when the user presses it will be down, and finally when the user releases the key it will be up again. Test for this sequence in the array that you get back from IDirectInputDevice::GetDeviceState().

thanks

##### Share on other sites
this only works with moving 1 item/per keypress

  bool down=0;if(keydown&&!down){  //process...  down=1;}else if(keyup&&down)  down=0;

extended waranty, how can I lose!

##### Share on other sites
Or even better, used Buffer Mode input so that you won''t miss any keystrokes due to too few UpdateState()''s.

##### Share on other sites
Do not use DirectInput in this situation, instead use windows messages handler, the WindProc, to handle keyboard key presses. It works a gazillion times better in this situation. You can use it simultaneously with DI.

Possibility

##### Share on other sites
DInput buffered is pretty much equivalent (and a little more reliable) than Windows messaging here, because you can tell it to work even if your application loses focus etc. Plus if you already have DInput set up...

Also using DInput you can bypass the standard Windows messaging loop... which is helpful if you have an exclusive-mode application.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001835
×