How to find if a key has been released

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
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

How to find if a key has been released

Post by Anteater »

Hi. How do you find out if a key has been released? I know how to find out if a key has been pressed, but I need to know if it's been released. Here's my event code:

Code: Select all

//events
       class EventR : public IEventReceiver
       {
             public:
                    virtual bool OnEvent(SEvent event)
                    {
                            if (event.EventType == EET_KEY_INPUT_EVENT)
                            {
                                                if (event.KeyInput.Key == KEY_KEY_W)
                                                {
                                                                     walking = true;
                                                }
                                                
                                                
                                                
                                                
                            } return false;
                    }
       };
       
       EventR receiver;
       device->setEventReceiver(&receiver);
As you can see, when W is pressed it sets walking to true, I want to also have it so when W is released it's set to false.
Thanks for any help.
Jin
Posts: 7
Joined: Tue May 16, 2006 4:15 pm
Location: Ontario, Canada

Post by Jin »

This might work:

Code: Select all

//events 
       class EventR : public IEventReceiver 
       { 
             public: 
                    virtual bool OnEvent(SEvent event) 
                    { 
                            if (event.EventType == EET_KEY_INPUT_EVENT) 
                            { 
                                                if (event.KeyInput.Key == KEY_KEY_W) 
                                                {
                                                                     walking = true; 
                                                }
                                                else
                                                {
                                                                    walking = false;
                                                }
                            }
		return false; 
                    } 
       }; 
        
       EventR receiver; 
       device->setEventReceiver(&receiver);
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

walking = event.KeyInput.PressedDown;

see http://www.irrforge.org/index.php/Keyboard_Input
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post by Anteater »

Thanks.
Post Reply