Re: Key press



Jean-Yves Lamoureux <jylam lnxscene org> writes:
> Hi 
> I've a problem to get current keyboard status. 
> (MyWindow->image is a DrawingArea)
> 
> I wonder where is the problem. I tell gtk to grab KEY_PRESS, with the right 
> mask. Then I link a function to the press and release events, but nothing 
> happens, function's not called. If someone can help me ...
> Thanks a lot
> 
> 
>   gtk_widget_add_events (GTK_WIDGET (MyWindow->image), GDK_KEY_PRESS_MASK);
>   gtk_signal_connect (GTK_OBJECT (MyWindow->image), "key_press_event",  
> GTK_SIGNAL_FUNC (LastKeyPressed), NULL);  
>   gtk_signal_connect( GTK_OBJECT (MyWindow->image),
> 		      "key_release_event",
> 		      LastKeyPressed,
> 		      NULL);


See the sentence about "to receive keyboard events" at the end of the
Description section for 2.0 drawing area docs:
  http://developer.gnome.org/doc/API/2.0/gtk/gtkdrawingarea.html

In 1.2 it's somewhat more complicated, in addition to setting
GTK_CAN_FOCUS you need to handle focus in/out events by
setting/unsetting the GTK_HAS_FOCUS flag.

You also need the area to have focus, obviously, usually the user
would tab to it to focus it.

If you don't want to worry about where the focus is, maybe you want to
get key events on the toplevel window instead of a particular widget.

Havoc



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