Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

I want to use the arrow keys as acontrol in my application, but GTK+ keeps stealing the key press events to move the focus around.

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.

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire