CeguiDotNet KeyDown event handling problem


02-04-2006 17:06:31

I'm trying to handle the KeyDown event for a CEGUI Editbox, but the value I'm getting passed to my CeguiDotNet.KeyEventArgs.scancode property seems to always be the same value, no matter what key I press, and it is not a value that is defined in the CeguiDotNet.Key.Scan enumeration (the value i'm getting no matter which key i press is 458759)... Not sure if this is an issue with the way I'm setting up my event handler:

//set up handler
ebUsername.KeyDown+=new CEGUI.KeyEventDelegate(this.UsernameCharacterKey);

//handler function definition
protected bool UsernameCharacterKey(CEGUI.KeyEventArgs e)

BTW, CEGUI is an alias for CeguiDotNet... My handler is being called, it just seems like the scancode value is either not being set properly, or I'm not using it properly...
Has anyone successfully implemented a KeyDown handler? Thanks for the help,


02-04-2006 17:27:18

Huh... there's plenty of examples of how to do this in C# in the demos included with ODN. And I have never had a problem with doing it in VB.NET.

It sounds to me like the keycode is possibly some sort of memory address rather than the correct number... Hmmmmm...

I'm fairly certain you learned how to set this up from the ODN demos, so referring you back to them would be kinda pointless. Anyone else have any idea what it is?


02-04-2006 17:30:40

I actually didn't see any examples of handling the KeyDown event of CEGUI in the ODN samples... the samples all grabbed keys using the Ogre event queue... did i miss a sample that uses CEGUI to handle the key events? I'm double-checking them now to see what I missed...


02-04-2006 17:47:04

OH! Duh, that's the problem... sorry I missed it.

You're probably capturing the OGRE scancode in the CEGUI event...

What you need to do is "inject" the keycode from Ogre in to CEGUI.

IN your Ogre keydown and keyup handler, you need to inject the key stroke.

Or are you doing that already?


02-04-2006 17:53:37

my key press event handler for ogre currently looks like this:

protected virtual void KeyPressed( KeyEvent e )

CEGUI is working, in that the Editboxes get all the characters and operate correctly... So I am thinking that CEGUI itself must be getting the correct information it needs in order to work... I think there is just some disconnect in the way I'm reading the scancode in... but I haven't been able to solve it yet


02-04-2006 19:59:03

There is a bug in CeguiNet/EventHandler.h in the way it handles EventArgs. It tries to create a new CEGUI::EventArgs and copy the one passed to it in HandleCEGUIEvent. But it could be any of the classes derived from CEGUI::EventArgs where EventHandler uses it just as the base class.

Insted of trying to create a new CEGUI::EventArgs, EventHandler could just hold a pointer to the passed arg. I tested this and it seems to work. but I'm not sure if that's the proper way to handle it.

Ill post again after I check if that it doesn't mess with anything else.


02-04-2006 20:09:29

Thanks for the point in the right direction! I've been digging through all the event code since I kind of figured it might be a problem somewhere in there, but not being all that familiar with CEGUI itself, and then tossing in the SWIG stuff, as well as being new to c#, I haven't been able to find the problem. I'll follow your lead and test the fix you are mentioning.


02-04-2006 20:28:42

Your fix seems to work for me, at least in the testing I have done so far... I guess as long as the EventArgs instance that we are point to is going to remain valid as long as we will be using it, then the fix will be fine? Just for reference this is what I am doing:

bool HandleCEGUIEvent(const CEGUI::EventArgs& e)
//2006-04-02 original code
//*this->mEventArgs = e;

//2006-04-02 fixed code
this->mEventArgs = (CEGUI::EventArgs*)(&e);



EventHandler( CEGUI::Window * window, const CEGUI::String & eventname )
//2006-04-02 removed
//mEventArgs = new CEGUI::EventArgs();
mEventFunctionPointer = NULL;
window->subscribeEvent( eventname, Event::Subscriber(&EventHandler::HandleCEGUIEvent, this));


02-04-2006 20:36:18

you got it :) just 2 lines to change.

I looked over how it's being used and didn't see any problems running it. So soon as developer cvs is working again ill update it :)


02-04-2006 20:39:49

Thanks for the quick help on this one, I just started moving all my stuff to c# because I figured it was time to move to .net, and this is a hurdle I probably couldn't have gotten over on on my own!