Key input doesn't work

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
MedievalMagic13

Key input doesn't work

Post by MedievalMagic13 »

Hello everybody. I have a problem with keys in Irrlicht. When I want to close my program with the ESC key, it doesn't respond to it. Actually, every action I want to do doesn't work. I've tried it witch several keys and codes, but it doesn't seem to work. This is my code for shutting down the program:


...

IrrlichtDevice *device = NULL;
SEvent event;

scene::ICameraSceneNode* camera = 0;

class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (camera)
return camera->OnEvent(event);

if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_ESCAPE &&
event.KeyInput.PressedDown == false)
{
// user wants to quit.
device->closeDevice();
}

return false;
}

};

...

I put this code before all the other code (except for namespaces and headers).

Does somebody know what's wrong with it?

Thanks.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

thats because you're sending all of your events to the camera, and automatically returning the result.

either put your key handlers above the Camera code, or when the camera returns check to see if it returned false- and if so, try to handle the event yourself.
a screen cap is worth 0x100000 DWORDS
MedievalMagic13

Post by MedievalMagic13 »

Thanks for the answer Keless. I'll try it out as soon as possible.
MedievalMagic13

Post by MedievalMagic13 »

:( It doesn't work. I can see the windows taskbar when I press ESC, but the program doesn't want to close, instead it's totally jammed.

This is my code at the moment (if I did it the right way):



SEvent event;

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)
{
// user wants to quit.
device->closeDevice();
}


if (camera)
return camera->OnEvent(event);


return false;
}

};


Did I do something wrong (I hope so)? If so, could somebody please show me his/her code about how to close the programs?
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

You can remove the first global define of "SEvent event". It's being overlayed by the SEvent event in your OnEvent().

The other piece is that your main loop needs to check if the device is still there, if not.. end.

The tech demo does this.
Crud, how do I do this again?
MedievalMagic13

Post by MedievalMagic13 »

Thanks for your reply Saigumi (and of course also thanks to Keless).
It works perfect now. :D I removed the global SEvent en included a check for the device in the main loop, like you said. Thanks a lot.
Post Reply