capturing keys press/realease



i try to register a callback function this way:
  gtk_signal_connect( GTK_OBJECT (window),
                               "key_press_event",
                               cb_keypress,
                               NULL);
  gtk_signal_connect( GTK_OBJECT (window),
                               "key_release_event",
                               cb_keypress,
                               NULL);

where cb_keypress is the following:

void cb_keypress( GtkWidget *widget,
                  GdkEvent  *event,
                  gpointer   callback_data ) {
 switch(event->type) {
  case GDK_KEY_PRESS:
   printf("KEY PRESSED\n");
   break;
  case GDK_KEY_RELEASE:
   printf("KEY RELEASED\n");
   break;
 }
};

i was thinking that when a key is pressed i should read on stdout
"KEY PRESSED" (just one time, even if i,m still leaving my finger on the
keyboard) and
when i get off the key, i should read "KEY RELEASED".
But i get it's not that!
It's like gtk (or the X server) is keeping for me memory of the key
pressed, and still sending me
the information, until nobody its pressing the key.
can any one help me?


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