Re: Key presses



Paul Davis wrote:
> In message <20010731095219 Q15368 ispi net>you write:
> >On Tue, 31 Jul 2001, Jean-Christophe Berthon wrote:
> >> Maybe try to use the key_press event on the gtk widget that is involved.
> >> something like :
> >>   gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
> >>                       GTK_SIGNAL_FUNC (on_window_key_press_event),
> >>                       NULL);
> >> where on_window_key_press is a function with this prototype :
> >> gboolean
> >> on_window_key_press_event           (GtkWidget       *widget,
> >>                                         GdkEventKey     *event,
> >>                                         gpointer         user_data);
> >>
> >
> >Right, that will do it for a specific widget. Is there a way to achieve
> >the same thing for an entire app, independent of which widget has the
> >focus?
> 
> 1) no, the above is not *widget* specific. its window specific, since
>    "window" in the above code is a top-level GtkWindow, not widget->window.
> 
> 2) if you really need it across the entire app, you can install a
>    key snooper. search the archives from about 2 months ago for a post
>    on doing this in GTK+.

Another option is to add a keyboard accelerator ... this is the mechanism GTK
uses for the <ctrl>Q or whatever keyboard menu shortcuts. Unfortunately it's
rather (ahem) weakly documented, as far as I know.

An easy hack is to make an invisible menu item with your key combination as a
shortcut, and connect to "activate" on the menu item. You won't get an (x, y)
position though (did you want that?).

John




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