#### Archived

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

# Simple Input Problem

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

## Recommended Posts

Hi, I have a small problem. When controlling something say a spaceship, you press and hold the button controlling it to turn and go forward etc. so, its simple, just check to see if the button is pressed (btw i''m using direct input), The problem is here: I want the button ''q'' bring me back to the main menu, but then in the main menu, the button ''q'' should make me quit the program entirely. If i however use the same method as above, pressing ''q'' will quit the game instead of going to the main menu unless i was lucky enough to let go of the key quickly enough. How would i go by doing this, using only DirectInput?

##### Share on other sites
I would do this the same way people seem to control buttons such as pause and stuff, to make sure they don''t react repeatedly to the same key press. When the key goes down, set a global flag that says the key has been pressed. Then when it first goes up, clear the flag. This means that when you check the key, you must check like this:

if(KEYDOWN(DIK_Q) && !qKeyPressed)
{
qKeyPressed = !qKeyPressed;
}
else if(!KEYDOWN(DIK_Q) && qKeyPressed)
qKeyPressed = !qKeyPressed

I hope this is right, but I''m pretty sure it is. And I hope it helps.

------------------------------
Jonathan Little
http://www.crosswinds.net/~uselessknowledge

thx

##### Share on other sites
If you dont mind the game pausing, use:

if (KEYDOWN(DIK_Q)){  while (KEYDOWN(DIK_Q);  gameState = GAME_STATE_MENU;}

---------------
kieren_j

##### Share on other sites
Heres a very good way to do it (I use it, and it works, in other words ). BTW, you need two seperate variables:
if(DIKEYDOWN(DIK_Q))
{
if(!Q_Pressed_Last_Cycle)
{
Q_Down = true;
}
else
{
Q_Down = false;
Q_Pressed_Last_Cylce = true;
}
}
else
{
Q_Pressed_Last_Cylce = false;
Q_Down = false;
}

Edited by - Zipster on 4/5/00 3:43:09 PM