keypress from a drawing area
- From: "frederik jensen" <frederik_jensen get2net dk>
- To: <gtk-list gnome org>
- Subject: keypress from a drawing area
- Date: Mon, 19 Feb 2001 04:08:43 +0100
/********************
Hello gtk-list.
Please consider the following program.
In the last gtk_signal_connect() we would like to print out keypress events, but we
cannot. However, when (darea) is replaced by (window) we receive the keypress
events. Presumably the key press event falls through the darea to the main window.
Is there any way to connect the key press event with darea instead of the main
window?
Thank you, Frederik Jensen.
********************************/
#include <stdio.h>
#include <gtk/gtk.h>
gint darea_keypress (GtkWidget *widget,
GdkEventKey *event) {
printf("I got key %d\n", event->keyval);
return TRUE;
}
gint destroy (GtkWidget *widget,
GdkEventExpose *event,
gpointer *data) {
gtk_main_quit ();
}
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_drawing_area_size (GTK_DRAWING_AREA (darea), 100, 100);
gtk_widget_show (darea);
gtk_widget_set_events (darea, GDK_KEY_PRESS_MASK);
gtk_container_add (GTK_CONTAINER (window), darea);
gtk_signal_connect (GTK_OBJECT (window),
"destroy",
GTK_SIGNAL_FUNC (destroy), NULL);
/* CHANGE "darea" TO "window" TO GET KEY PRESS EVENTS ... */
gtk_signal_connect (GTK_OBJECT (darea),
"key-press-event",
(GtkSignalFunc) darea_keypress,
NULL);
gtk_widget_show (window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]