Re: Need advice on key_press_event.




Preben Randhol <randhol@pvv.org> writes:

> Hi
> 
> We have made a canvaswidget (not the Gnome canvaswidget) that can be
> scrolled up and down. What I know want to do is to add keybindings for
> Pg_Down and Pg_Up (and some other keys as well). 
> 
> I can do this with an eventbox attached to the canvaswidget, but that
> requires that the widget has focus. I would very much like to be able
> to press Pg_Down no matter which widget has focus (perhaps except
> entry/combobox widgets though) and get the canvas to scroll.
> 
> How would you go about to do this? Is there a mechanisme for doing
> this. As the menu has shortcuts that work without the menubar having
> focus, I thought there might be one.

Well, there are a couple of ways of doing it. You can use
the accelerator mechanism. This basically does a binding
of 

 key press on top level window => signal emission

You presumably already have an accelerator group if you
have a menu where key bindings work, so you'd just
need to call gtk_accel_group_add().

The other way to do this is just to connect to 
"key_press_event" on your toplevel window. All key presses
get redirected to the toplevel window before being
sent to the focus widget.

Regards,
                                        Owen




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