I have searched the forums and found a topic like this but the event receiver messed up the FPS camera in irrlicht(it wouldnt allow the camera to move using the keyboard) so that's not an option. How else can I do this?
EDIT: I fixed the problem with the MyEventReceiver so that is now an option again and I tried that but when i do that and push escape i get the windows xp "this program has encountered an error" message. What have I done wrong? The code I'm using is
class TraitementDesMessages : public IEventReceiver
{
public:
// c'est ici qu'on récupère les évènements
virtual bool OnEvent(SEvent event)
{
// si c'est un évènement clavier ça nous intéresse
if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.PressedDown)
{
//if(keys[irr::KEY_KEY_O]) k=1;
switch ( event.EventType )
{
case EET_KEY_INPUT_EVENT:
{
if ( event.KeyInput.Key == KEY_SPACE && event.KeyInput.PressedDown )
{
k = !k; // don't do gr = !true, [ unless you're intending to toggle the value of gr, I'll show how to do that below ] believe it or not, that takes slightly more processing, it causes the compiler to generate a temporary varaible on the stack, to hold the value of !true, then assigns that value to gr, then removes the temporary variable off the stack. it's faster to just set it to true or false
}
if ( event.KeyInput.Key == KEY_SHIFT && event.KeyInput.PressedDown ) // BASCULE SHIFT
{
sp = !sp; // to toggle the value of sp, when the key is pressed, there's another problem here though, in that you need to handle the event so it's only processed once each time the key is pressed. Right now this will constantly toggle the value of sp as long as the SHIFT key is pressed down
}
if ( event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown )
{
noesc = false; // don't do gr = !true, [ unless you're intending to toggle the value of gr, I'll show how to do that below ] believe it or not, that takes slightly more processing, it causes the compiler to generate a temporary varaible on the stack, to hold the value of !true, then assigns that value to gr, then removes the temporary variable off the stack. it's faster to just set it to true or false
}
}
return false;
}
}
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
lmb = true;
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
lmb = false;
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
rmb = true;
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
rmb = false;
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN)
mmb = true;
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP)
mmb = false;
// retourner false veut dire qu'on n'a pas traité l'évènement
// et si on passe ici, c'est qu'on a reçu un évènement qui ne nous
// intéressait pas, donc on l'a pas traité donc on retourne false
return false;
}
};