Simultaneous Key Events
Posted: Thu Dec 29, 2005 2:53 pm
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...
to move in a certain direction i've done the following...
forward for example:
is there a better way to do all this?
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;
};
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);