Re: Simluating Keypresses



On Wed, 8 Dec 2004, andrew gatt wrote:

I'm very new to Gtk so please forgive me if this is an obvious question,
i've done a lot of digging and can't find an answer. What i've got is a Gtk
front end with other control threads running which process commands from
other ports. I need to simulate key presses on the window from these other
threads. For example a "move left" command on the serial port is received by
my serial routine and sent to the Gtk main thread, that moves the focus
left, one button, on the main window.

What i've tried so far is...

Here is what I use (not original):

static void manufacture_keystroke (GtkWidget *widget, guint uval)
{
    GdkKeymapKey *keys;
    gint n_keys;

    if (gdk_keymap_get_entries_for_keyval(NULL, uval, &keys, &n_keys)) {
        guint16 hardware_keycode;
        GdkEvent *event;

        hardware_keycode = keys[0].keycode;
        g_free(keys);

        event = gdk_event_new(GDK_KEY_PRESS);
        event->key.window = g_object_ref(widget->window);
        event->key.hardware_keycode = hardware_keycode;

        event->key.keyval = gdk_unicode_to_keyval(uval);
        event->key.length = 1; /* ? */

        event->key.send_event = FALSE; /* ? */
        event->key.time = GDK_CURRENT_TIME;

        gtk_main_do_event(event);
        gdk_event_free(event);
    }
}

Allin Cottrell



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