Handle multiple inputs at the same time?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Browndog
Posts: 74
Joined: Thu Aug 18, 2005 2:53 am

Handle multiple inputs at the same time?

Post by Browndog »

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.
Zoulz

Post by Zoulz »

how about:

if(keyPress == LEFT && keyPress == UP)
{
doStuff(1);
}
else if(keyPress == LEFT && keyPress = DOWN)
{
doStuff(2);
}
else if(keyPress == LEFT)
{
doStuff(3);
}
Browndog
Posts: 74
Joined: Thu Aug 18, 2005 2:53 am

Post by Browndog »

Yeah I think that may work.

I guess I just have to have every combo covered. I'll give it a shot.

If anyone has a better method let me know :).
bitmapbrother
Posts: 34
Joined: Wed Aug 10, 2005 6:15 am

Post by bitmapbrother »

No this will not work keyPress cant eq to two values ...
William Finlayson
Posts: 61
Joined: Mon Oct 25, 2004 12:11 am

Post by William Finlayson »

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.
Browndog
Posts: 74
Joined: Thu Aug 18, 2005 2:53 am

Post by Browndog »

ah ok ic sounds interesting I'll give it a shot
Post Reply