Getting Keystrokes at 30 fps

Started by
5 comments, last by james86 21 years, 1 month ago
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
Advertisement
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
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!
extended waranty, how can I lose!
Or even better, used Buffer Mode input so that you won''t miss any keystrokes due to too few UpdateState()''s.
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
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.

This topic is closed to new replies.

Advertisement