Slowing down input

Started by
7 comments, last by themadme 14 years, 1 month ago
Ok I'm working on a game right now and I'm creating a main menu system where I display buttons and when you press up or down on either the key board, or an XBOX360 controller that the selected button is changed. The problem I am having is that when you press the keys on the keyboard or the dpad on the controller it races through changing the selection so you see it highlight the different menu options very fast as it reads the inputs very quickly. I'm doing this in DirectX 9, using XInput for the controller and DirectInput for the keyboard any ideas for how to slow this down?

Darcmagik

Of all the things I've lost I miss my mind the most.

Advertisement
Do you have a timer of some kind? You could change the menu selection only if a certain amount of time has passed since the last time a key was pressed.
"All you have to decide is what to do with the time that is given to you." - Gandalf
In your input processing function, you should store two values. You need to store the collection of input from the current frame, and you need to keep the input from the previous frame.

When you're checking for input, you need to make sure that during the current frame, the button is pressed, and that during the last frame, the button is released. If both those conditions are true then you should increment the selected option on the screen.
Well, maybe I'm doing my timing wrong, I'm working through a book on DirectX9 and in the book the author has us use if (GetTickCount() - start >= 30), start is set to GetTickCount() when the app starts running. I know there is a better way to do timing when it comes to this but I just don't know what it is?

Darcmagik

Of all the things I've lost I miss my mind the most.

Also I am working on building a framework of my own for making games, and one of the things that I'm trying to figure out what to do is, should I put all DirectX related functionality, helper functions, etc... in 1 header and cpp file, or should I have a one set of files for graphics, one set of files for audio, one set of files for input, and a file for the windows related code, and another set of files for the actual game?

I'm trying to figure out the best way to organize things so that it works best.

Darcmagik

Of all the things I've lost I miss my mind the most.

are you making sure to reset start?

you should really use
DWORD newtime = GetTickCount();
if(newTime - start >= 30){
//////////////////////////
// Your handling code here
//////////////////////////

start = newTime;
}
-Matt S.
For keyboard clicks you'll want to add a delay between repeated clicks.

Event: Key pressed
Case 1: Key is just pressed --> Change Selection
Case 2: Key is a REPEAT:
Case 2.1: Delta < Threshold --> Add to delta
Case 2.2: Delta >= Threshold --> set Delta=0, Change Selection



For the xbox controller however, i assume its behaving more like a mouse\mousewheel?
In which case you will have to check the distance traveled.

Event: moved controller
Case 1: Delta < threshold --> Add delta to threshold
Case 2: Delta >= threshold --> Set delta to 0, Change selection

My assumption about the xbox controller could be wrong, in which case you probably handle it as a keyboard event.
Don't use DirectInput for keyboard (or mouse) input. Use WM_KEYDOWN instead, that'll give you keyboard repeat as you expect. For the 360 controller you'll need to implement key repeat yourself though.
Excuse me for not understanding this but to stop from cursor moving up and down fast is a simple solution.

All you need to do is have an if statement and boolean, example:

//global variable;
bool bPressed = false;

if(pInputMgr->getMouseKeyboard()->bKeyPressed(LEX::KEYS::_SPACE_) && !bPressed)
{
// do your code stuff here
bPressed = true;
}else if((pInputMgr->getMouseKeyboard()->bKeyReleased(LEX::KEYS::_SPACE_))
{
bPressed = false;
}

From above the cursor will only move if the user presses a button once, you coudl modify this to use a timer instead of a boolean

This topic is closed to new replies.

Advertisement