Re: generating keyboard events
- From: Peter Gasper <pgasper designadvantage com>
- To: gtk-app-devel-list gnome org
- Subject: Re: generating keyboard events
- Date: 04 Nov 2003 09:28:25 -0700
Ok so I've worked on it a little more but still no luck. Does anyone
have a working example they can point to? Thanks.
test()
{
gint n = 0;
GdkKeymapKey **keys = new GdkKeymapKey*[100];
// 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 = tmp->window;
tmpkey->send_event = FALSE;
tmpkey->time = GDK_CURRENT_TIME;
tmpkey->state = 0;
tmpkey->keyval = GDK_KP_Enter;
tmpkey->length = 0;
tmpkey->string = NULL;
if( gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
GDK_KP_Enter, keys, &n ) )
{
tmpkey->hardware_keycode = keys[0]->keycode;
tmpkey->group = keys[0]->group;
}
else // failed - no combination to get that.
{
delete event;
g_free(keys);
return;
}
// post our event
gdk_event_put(event);
gdk_flush(); // don't know if need this, didn't make any difference.
//setup 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);
gdk_flush();
delete event;
g_free(keys);
}
On Sat, 2003-11-01 at 19:38, Peter Gasper wrote:
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]