Re: [gtk-list] How to get keyboard input




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






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