Re: key input get grab by other widget



>My application has a drawing-area, menu, and a frame with check-button in it.
>
>In the drawing-area, I assign "key press event" to it. It work find for key
>like "a" and "b", but does not work for arrow key. Once I press a arrow key,
>the "check button" grab that input, and subsequently, all key is grab by the
>"check button". The same will happen if I point at the menu-bar and click in a
>empty space following by pressing a key. What I need is:
>
>If the pointer is in the drawing-area, drawing-area should grab all key event.

the arrow buttons, tab key and enter key are all considered "special"
by GTK+, and are used (by default) to move the keyboard focus around
between widgets. there is no way to turn off this behaviour in a
global sense, but it can be handled on a per-widget basis.

if you have a widget that needs to be able use any of these keys as a
"normal" key, you need to connect to the widgets "key_press_event"
signal with a handler that does something like this:

   gint
   key_press_handler (GtkWidget *widget, GdkEventKey *event, gpointer data)
   {
         int stop_emission = FALSE;

         switch (event->keyval){
	 case GDK_Up:
         case GDK_Down:
         case GDK_Left:
	 case GDK_Right:
	         stop_emission = TRUE;
                 break;
         default:
	         break;
         }
	 
	 if (stop_emission) {
	      /* don't let the rest of GTK+ see this key */
	      gtk_signal_stop_emit_by_name (GTK_OBJECT(widget), 
					    "key_press_event");
         }
	 
	 .... rest of your conventional key handling ...

         return TRUE;					    
   }

--p







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