Re: [gtkmm] Assigning callbacks to function-key presses



>How can I assign functionality to the function-keys, F1-F12, in a gtkmm
>application?
>Actually I have eight buttons, and would like F1-F8 to activate these
>buttons.  (Alternatively the function keys could just be connected with the
>same callbacks as the buttons).

gint
SomeObject::key_press_handler (GdkEventKey *event)
{
     switch (event->key) {
     case GDK_F1:
         do_f1_thing ();
	 break;
     case GDK_F2:
         do_f2_thing ();
         break;
     ...
     }
     return TRUE; // or FALSE, depending
}

and somewhere else:

  Gtk::Window some_window;
  
  some_window.key_press_event.connect 
     (slot (*someObject, &SomeObject::key_press_handler));

the event names for gtkmm2 are slightly different. you may prefer to
use the key release rather than the key press, in which case you may
have to request this event for the widget in question (some/many GTK
widgets don't ask for this event for some odd reason).

accelerators are a different way of doing this. i have never used them.

--p




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