[?] Handling key_press_events



Hello,
I have problems with key_press_event from a drawing area. In the following 
short program button_press_events are handled as described in the
tutorial but 'key_press_event' is never called. Any hints what I am doing
wrong?

/**********************************************************************
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>

gint
button_press_event(GtkWidget *widget, GdkEventButton * event, gpointer
data)
{
    g_print("*** Button press event ***\n");
    return FALSE;
}

gint
key_press_event(GtkWidget *widget, GdkEventKey * event, gpointer data)
{
    g_print("*** Key press event ***\n");
    return FALSE;
}

int
main(int argc, char *argv[])
{
  GtkWidget *window, *darea;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  darea = gtk_drawing_area_new();
  gtk_container_add(GTK_CONTAINER(window), darea);

  gtk_widget_set_events(GTK_WIDGET(darea),
                        GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK);
  gtk_signal_connect(GTK_OBJECT(darea), "key_press_event",
                     GTK_SIGNAL_FUNC(key_press_event), NULL);
  gtk_signal_connect(GTK_OBJECT(darea), "button_press_event",
                     GTK_SIGNAL_FUNC(button_press_event), NULL);

  gtk_widget_show_all(window);

  gtk_main();
  return 0;
}

--
Peter Schoefer 
email: ps@snafu.de



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