[9030] in The GTK GIMP ToolKit mailing list archive
[gtk-list] Re: How to get keyboard input
daemon@ATHENA.MIT.EDU (Havoc Pennington)
Sat Oct 3 11:00:19 1998
Date: Sat, 3 Oct 1998 09:59:28 -0500 (CDT)
From: Havoc Pennington <rhpennin@midway.uchicago.edu>
Reply-To: Havoc Pennington <rhpennin@midway.uchicago.edu>
To: gtk-list@redhat.com
In-Reply-To: <m37lyh69g7.fsf@localhost.localdomain>
Resent-From: gtk-list@redhat.com
On 3 Oct 1998, Ray Crampton wrote:
>
> How do I retrieve keystrokes as they come in?
>
From a recent gtk-app-devel post:
gint key_cb(GtkWidget* w, GdkEventKey* event, gpointer data)
{
switch(event->keyval) {
case GDK_Up:
g_print("Up arrow key!");
break;
case GDK_F1:
g_print("F1!");
break;
/* etc. */
Look at gtk+/gdk/gdktypes.h for all the event structs. Some of the members
are pretty self-explanatory (others aren't). ;-)
If you have a book that talks about X events, you can see the X-->Gdk
conversion in gtk+/gdk/gdk.c. It may be helpful sometimes.
The above callback connects to key_press_event or key_release_event on a
widget. Your widget needs to have a window (i.e.
GTK_WIDGET_NO_WINDOW(widget) is false) and you have to set_events before
the widget is realized requesting GDK_KEY_PRESS_MASK (or
KEY_RELEASE_MASK).
Havoc
--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null