Page 1 of 1

Simultaneous Key Events

Posted: Thu Dec 29, 2005 2:53 pm
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?

Posted: Thu Dec 29, 2005 3:18 pm
by mepcotterell
nevermind... i got it to work perfectly using bool keys method