Escape button to exit program?

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
sugarhigh
Posts: 14
Joined: Sat May 28, 2005 4:11 am

Escape button to exit program?

Post by sugarhigh »

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

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public :
virtual bool OnEvent(SEvent event)
	{
		if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown == false)
		{
			device->closeDevice();         
		}

		return false;
	}
};
ab illo cui multum datur multum requiritur
AmigaIrr
Posts: 94
Joined: Mon Jan 10, 2005 7:55 am
Location: France, Alsace

Post by AmigaIrr »

try this :

Code: Select all

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;
	}
};
[/code]
L'eternité c'est long, surtout vers la fin...

Q6600 triton 79, 4 GO, 2* RAPTOR 150GO of ARECA 256 RAID 0, 3870 Zalmann, P5K. 24" Samsung. Antec nine hundred
Post Reply