Input Receivers

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
Micken

Input Receivers

Post by Micken »

*sigh* more problems!

i'm trying to handle some keyboard inputs but it seems irrlicht just doesn't want to listen to my keyboard!

Everything runs fine but it's not recognizing any keypresses at all no matter what i try. here is my code:

Code: Select all

class MyEventReceiver : public IEventReceiver 
{ 
    u8 keys[KEY_KEY_CODES_COUNT]; 

public: 

    virtual bool OnEvent(SEvent event) 
    { 
       if (event.EventType == irr::EET_KEY_INPUT_EVENT)    
            if (event.KeyInput.PressedDown && keys[event.KeyInput.Key]==0 ) { 
               keys[event.KeyInput.Key]=1; 
            } 
            if (!event.KeyInput.PressedDown && keys[event.KeyInput.Key]!=0) { 
               keys[event.KeyInput.Key]=0; 
            }    
         return true; 
    } 
    
    bool isKeyDown(u8 keycode) { 
        if (keys[keycode]!=0) 
                return true; 
        return false; 
    } 
    bool isKeyPressed(u8 keycode) { 
        if (keys[keycode]==1) { 
                keys[keycode]=2; 
                return true; 
        } 
        return false; 
    } 
    
    void resetKeyboard(void) { 
        int i; 
        // set initial keystates to false 
        for (i=0; i<KEY_KEY_CODES_COUNT; i++) 
                keys[i]=0; 
    } 
};
that's basically AndyH's event receiver code

Code: Select all

int main()
{

	MyEventReceiver receiver;

	IrrlichtDevice *device = createDevice(video::EDT_DIRECTX8,
		core::dimension2d<s32>(640, 480), 16, false, false, &receiver);

	device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
and when i check for the key if it's been pressed i use

Code: Select all

			receiver.resetKeyboard();

			if (receiver.isKeyDown(KEY_LCONTROL))
				repelState = REPEL_GO;
sry if i'm such a n00b.
thanks!
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Your receiver should always return false. Only return true if there was a key event or whatever... ;-)

virtual bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
if (event.KeyInput.PressedDown && keys[event.KeyInput.Key]==0 ) {
keys[event.KeyInput.Key]=1;
}
if (!event.KeyInput.PressedDown && keys[event.KeyInput.Key]!=0) {
keys[event.KeyInput.Key]=0;
}
return true; //Change this to return false;
}
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
Micken

Post by Micken »

hmm, that didn't seem to work, thanks anyways though, i'll figure it out eventually after making a fresh start.
Post Reply