define key troubles

I’m having a small problem with define_key. I would like define key to access the below function. However, when ever I build I get this error:

‘keyObject::key_down’: function call missing argument list; use ‘&keyObject::key_down’ to create a pointer to member

define key call (KEY is a string variable):

window->get_panda_framework()->define_key(KEY, KEY, key_down, NULL);

function definition:

void keyObject::key_down(const Event * theEvent, void * data)
{	value++;	}

Something that’s common to happen when programming these methods is to forget to make it static. So, the declaration should be:

static void key_down(const Event * theEvent, void * data); 

And in the cxx you can just let it the same.

Does anyone know how to use non-static functions with define_key?

Instead of passing a NULL as the last parameter you pass a pointer to the object…

window->get_panda_framework()->define_key(KEY, KEY, key_down, this); 

and then:

void keyObject::key_down(const Event * theEvent, void * data){
   MyClass me = (MyClass*)data;

or you can do something like this, and implement your stuff on the second method:

static void key_down(const Event*, void* data){ ((MyClass*)data)->key_down(); }
void key_down(){
   // My Stuff;

Thankyou very much. I feel a little stupid now, but thankyou. :wink:

well, now I need to create buttons dynamically. Is there a way to do this?

I have messed around with PGButton_notify, but I have no idea how such an object tells when a button is clicked.

Your OP was talking about handling keyboard button events. Are you still referring to keyboard buttons when you talk about creating buttons dynamically, or are you now talking about onscreen GUI button elements? The PGButton class is for the purpose of creating an onscreen GUI button, and it works by generating an event when the button is clicked with the mouse.

But if you’re talking about creating keyboard buttons dynamically, what precisely do you mean?


Actually I’m refering to the GUI. I guess I should start a new thread.