Re: Simluating Keypresses



On 12/08/04 21:53, andrew gatt wrote:
Hello,

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:

GdkEvent* manual_event;

manual_event->type = GDK_KEY_PRESS;
((GdkEventKey*)manual_event)->keyval = GDK_Tab;
((GdkEventKey*)manual_event)->send_event = TRUE;    // Which i read shows
that the event was synthesized by the application and not X windows.

gtk_widget_event (window, manual_event);

Which compiles fine, but seg faults. Is it something i'm not setting up
properly?

that's because you're dereferencing a pointer to uninitialised memory.

you need to do something like:

GdkEventKey manual_event;
manual_event.type = GDK_KEY_PRESS;
manual_event.keyval = GDK_Tab;
manual_event.send_event = TRUE;
gtk_widget_event(window, (GdkEvent *)&manual_event);

note that i'm not sure that gtk_widget_event() is what you actually
want to do here, but your question ends up being a C programming question,
not a gtk question, so...

        -brian



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