generating keyboard events



I'm trying to generate keyboard events using gdk_event_put() in gtkmm.
The following code compiles and runs but does not generate any events.
Does anyone know of some example code that does this or what am I doing
wrong? 

Also, is there a good way to find the hardware_keycodes for a given key
or keyval?

Thanks.


// generate press event
GdkEvent *event = new GdkEvent();
event->type = GDK_KEY_PRESS;

// init any fields
GdkEventAny *tmp = (GdkEventAny*)event;
tmp->type = GDK_KEY_PRESS;
tmp->window = gdk_get_default_root_window();
tmp->send_event = FALSE;

GdkEventKey *tmpkey = (GdkEventKey*)event;
tmpkey->type = GDK_KEY_PRESS;
tmpkey->window = gdk_get_default_root_window();
tmpkey->send_event = FALSE;
tmpkey->time = GDK_CURRENT_TIME;
tmpkey->state = 0;
tmpkey->keyval = GDK_Left;
tmpkey->length = 0;
tmpkey->string = NULL;
tmpkey->hardware_keycode = 102; // hardcoded arrow key
tmpkey->group = 0;

// post our event
gdk_event_put(event);

//setup key release
event->type = GDK_KEY_RELEASE;
tmp->type = GDK_KEY_RELEASE;
tmpkey->type = GDK_KEY_RELEASE;
tmpkey->state = GDK_RELEASE_MASK;

// post our event
gdk_event_put(event);

delete event;


-- 
Peter Gasper <pgasper designadvantage com>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]