I need some help with key events

look at the program attached.

Do You Yahoo!?
Consiga gratis su dirección @yahoo.es en http://correo.yahoo.es
 * I want to catch keyboard events in a GtkGLArea widget, but I can't.
 * The code is similar to this, but with a GtkGLArea widget, and
 * not a GtkDrawingArea. Can't anyone help? 
 * Please, I'm very dissapointed, and I think that it isn't a bug
 * of the GTK+ library, so, where is my error?
 * Why does it catch mouse button events and no keyboard events??
 * Thank you, and sorry for my english (is as bad as my code ;)

#include <gtk/gtk.h>

GtkWidget *create_area (void);
gint key_press(GtkWidget *widget, GdkEventKey *event);
gint key_release(GtkWidget *widget, GdkEventKey *event);
gint button_press (GtkWidget *widget, GdkEventButton *event);

int main (int argc, char **argv)
        GtkWidget *window, *area;
        gtk_init (&argc, &argv);

        area = create_area ();

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_events (window, GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
  gtk_window_set_title (GTK_WINDOW (window),"GTK+ bug?");
  gtk_signal_connect (GTK_OBJECT(window), "delete_event",
                      GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

        gtk_container_add (GTK_CONTAINER (window),area);

        gtk_widget_show (area);
  gtk_widget_show (window);
  gtk_main ();
  return 0;

GtkWidget *create_area (void)
        GtkWidget *widget;

  widget = gtk_drawing_area_new ();

  gtk_signal_connect (GTK_OBJECT(widget), "key_press_event",
                      GTK_SIGNAL_FUNC(key_press), NULL);
  gtk_signal_connect (GTK_OBJECT(widget), "key_release_event",
                      GTK_SIGNAL_FUNC(key_release), NULL);
  gtk_signal_connect (GTK_OBJECT(widget), "button_press_event",
                      GTK_SIGNAL_FUNC(button_press), NULL);

        return widget;

gint key_press(GtkWidget *widget, GdkEventKey *event)
        g_print ("\nkey press event");
  return TRUE;

gint key_release(GtkWidget *widget, GdkEventKey *event)
        g_print ("\nkey release event");
  return TRUE;

gint button_press (GtkWidget *widget, GdkEventButton *event)
        g_print ("\nbutton press event");
        return TRUE;

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