Simulated keypress window focus



Hi,

I've recently been trying to implement a simulate
keypress function, the function is activated by a
command sent to the gui through a pipe, which is all
working however the simulate keypress function never
seems to actually work. The piece of code i'm using
is:

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.keyval = GDK_Tab;
        event->key.length = 1; /* ? */


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


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

Where i have forced the keyval to that of the tab
button for now. I pass in the pointer to the main
window. I'm trying to get the focus moved between
buttons on a window - i'll also want to be able to
simulate up, down, left, right and enter.

My first question is can anyone spot anything i'm
doing wrong?

Secondly does the main window need to be in focus for
this function to work. At the moment i type in a
command to the server app on the command line of a
terminal window, which puts the gui window out of
focus.

Thanks
Andrew




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