Simultaneous Key Events

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
mepcotterell
Posts: 10
Joined: Thu Dec 29, 2005 2:42 pm

Simultaneous Key Events

Post by mepcotterell »

I want to be able to handle multiple key presses at the same time... for example pressing up and right yields the code for up to run as well as the code for right. As my code stands now it will only handle one key press and not the other...

Code: Select all

class KeyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{ 
		
		if (event.EventType == EET_KEY_INPUT_EVENT)
		{ 	

			if (event.KeyInput.Key == KEY_KEY_W)
			{					
				do stuff
				
			}

			if ( event.KeyInput.Key == KEY_KEY_S)
			{
				do stuff
								
			}

			if (event.KeyInput.Key == KEY_KEY_D)
			{
				do stuff
				
			}

			if (event.KeyInput.Key == KEY_KEY_A)
			{
				do stuff
			}
				
		}
	}
	return true;
};
to move in a certain direction i've done the following...

forward for example:

Code: Select all

float speed = 4.0;

core::vector3df v = node->getPosition();
core::vector3df r = node->getRotation();

v.X = v.X + ( cos(r.Y * 3.14/180)*speed );
v.Z = v.Z - ( sin(r.Y * 3.14/180)*speed );
node->setPosition(v);
is there a better way to do all this?
mepcotterell
Posts: 10
Joined: Thu Dec 29, 2005 2:42 pm

Post by mepcotterell »

nevermind... i got it to work perfectly using bool keys method
Post Reply