To get input for my program I take inputs from the keyboard by overriding OnEvent in IEventReceiver I think have a series of if statments to control movement of a node ie.
if(keyPress==LEFT)
{
turnLeft(1);
refreshScreen();
}
and so on for right, up, down, etc...
How could make it so that 2 directions can be used at the same time?
ie if up and left are pressed at the same time I would like to go up and left.
Handle multiple inputs at the same time?
-
- Posts: 34
- Joined: Wed Aug 10, 2005 6:15 am
-
- Posts: 61
- Joined: Mon Oct 25, 2004 12:11 am
How about saving the key states between events as booleans
//(somewhere outside of event handler)
bool leftPressed=false, upPressed=false; //as many as you have actions
//(event handler)
if(keyPress==LEFT)
{
leftPressed = event->KeyInput.PressedDown;
}
else if(keyPress==UP)
{
upPressed = event->KeyInput.PressedDown;
}
//(maybe at end of event handler, maybe in main loop)
if(upPressed&&leftPressed) doUpLeftCombo();
else if(upPressed) doUpStuff();
refreshScreen();
That way, while the user is holding a key down, the value will be true, and when they release it will be false, then base your actions on the state of your set of booleans.
//(somewhere outside of event handler)
bool leftPressed=false, upPressed=false; //as many as you have actions
//(event handler)
if(keyPress==LEFT)
{
leftPressed = event->KeyInput.PressedDown;
}
else if(keyPress==UP)
{
upPressed = event->KeyInput.PressedDown;
}
//(maybe at end of event handler, maybe in main loop)
if(upPressed&&leftPressed) doUpLeftCombo();
else if(upPressed) doUpStuff();
refreshScreen();
That way, while the user is holding a key down, the value will be true, and when they release it will be false, then base your actions on the state of your set of booleans.