Frustrated with keyboard input

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
igpay
Posts: 5
Joined: Mon Oct 05, 2009 1:18 am

Frustrated with keyboard input

Post by igpay »

I just can't seem to get keyboard input to work! I never get any errors, but while running my application, no keypresses register. Hopefully it's just a small mistake that I am overlooking, maybe someone can help.

I am using the event receiver class used in the tutorials, it is the first thing I declare, right after my includes.

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
	// This is the one method that we have to implement
	virtual bool OnEvent(const SEvent& event)
	{
		// Remember whether each key is down or up
		if (event.EventType == irr::EET_KEY_INPUT_EVENT)
			KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;

		return false;
	}

	// This is used to check whether a key is being held down
	virtual bool IsKeyDown(EKEY_CODE keyCode) const
	{
		return KeyIsDown[keyCode];
	}
	
	MyEventReceiver()
	{
		for (int i=0; i<KEY_KEY_CODES_COUNT; ++i)
			KeyIsDown[i] = false;
	}

private:
	// We use this array to store the current state of each key
	bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
The problem is that OnEvent is never actually called, even if I press keys.
I'm not sure what could possibly be causing this, has anyone else encountered this problem?
Epi
Posts: 9
Joined: Wed Mar 04, 2009 4:27 am

Post by Epi »

are you telling irrlicht to use your eventreceiver?
Lil Margin
Posts: 212
Joined: Sun Jul 19, 2009 4:24 am
Location: Netherlands Antilles, Curacao

Post by Lil Margin »

in your main int do this BEFORE the irrlicht device creation
MyEventReceiver receiver;

and declare your device like this :

if your using irrlicht 1.5

Code: Select all

IrrlichtDevice *device =
        createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
            false, false, false, &receiver);
if you using irrlicht 1.6

Code: Select all

IrrlichtDevice *device =
        createDevice(EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
            false, false, false, &receiver);
the irrlicht 1.6 one wasnt tested but is suppose to work...
anyway let me know how your problem went.
andres
Competition winner
Posts: 78
Joined: Tue Jul 08, 2008 5:18 pm
Location: Guarapuava/Brazil
Contact:

Post by andres »

Lil Margin wrote:in your main int do this BEFORE the irrlicht device creation
MyEventReceiver receiver;
you can set the event receiver after device creation using the command "setEventReceiver"
Prof. Andres Jessé Porfirio
Federal Technological University of Parana (UTFPR)
www.andresjesse.com
http://irrrpgbuilder.sourceforge.net

Image
igpay
Posts: 5
Joined: Mon Oct 05, 2009 1:18 am

Post by igpay »

Thanks you guys. I dont have time to try this right now, but I'm sure it'll work.
igpay
Posts: 5
Joined: Mon Oct 05, 2009 1:18 am

Post by igpay »

Got it. Thanks you guys.
Post Reply