Key press handling is somewhat complex. You might want
to read the
section called Keyboard Focus in the chapter
called GDK Basics and the section called
Focus in the chapter called GTK+ Basics
for a brief overview. the section called
Receiving GDK Events in GTK+ in the chapter
called GDK Basics is also relevant.
In short, key events are initially received by a
toplevel GtkWindow. GTK+'s
key event behavior is more or less defined by default
key press event handler in
gtkwindow.c (looking at this function is
instructive). It works as follows:
-
If there's a focus widget, the key event signal is
emitted on the focus widget. If this emission
returns TRUE, as
described in the section
called Receiving GDK Events in GTK+ in the
chapter called GDK Basics, processing
stops.
-
If any of the accelerator groups attached to the
window contain an accelerator matching the event,
then processing stops.
-
If the key event hasn't been handled yet, there are
some default bindings; the arrow keys move the
focus around, for example.
Thus, to override the arrow key behavior, you can
return TRUE from the
focus widget's signal emission, install an accelerator
for the arrow keys, or connect to
"key_press_event" on the toplevel window and use
gtk_signal_emit_stop_by_name() to end the signal
emission before the
GtkWindow default handler runs.