Re: I need some help with key events

G'Day !

What is your error ?

On my laptop, g_print( ) tends to give me a SEGFAULT when I use it (if switched
to populating a label in my main window to avoid headaches  ;-)

On my key presses, I specify particular keys I'm interested in via a switch (see
gdk header files).  Might try capturing one known key and see if that works.

I can send you working gtk_gl_area code if you want.

Jim Parker

Sailboat racing is not a matter of life and death ....  It is far more important
than that !!!

                    Pablo Barbachano                                                                          
                    <lordnene yahoo es>             To:     gtk-app-devel-list gnome org                      
                    Sent by:                        cc:                                                       
                    gtk-app-devel-list-admin        Subject:     I need some help with key events             
                    11/03/00 11:54 AM                                                                         

look at the program attached.

Do You Yahoo!?
Consiga gratis su dirección en*
 * 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,
  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]