Adds an accelerator (shortcut key) for the widget, so that the button/widget can be accessed by using the keyboard, without moving the mouse or tabbing through widgets.
signal is the name of a signal that should be invoked on the widget once the accelerator is pressed. For a button, you most likely want to pass clicked here.
accel_key defines the key to be pressed, see Symbolic names for keys to find the right one.
modifiers tells which additional button has to be pressed to emit the signal. Normally, you want to use Gdk::CONTROL_MASK (Ctrl key) or Gdk::MOD1_MASK (Alt key).
//Our window $wnd = new GtkWindow(); //Accelerator group $group = new GtkAccelGroup(); //Add group to window, making it active $wnd->add_accel_group($group); //"back" button $btn = GtkButton::new_from_stock(Gtk::STOCK_GO_BACK); $btn->add_accelerator( 'clicked', $group, Gdk::KEY_Left, Gdk::MOD1_MASK, 0 ); $wnd->add($btn);
In this example, you can use the shortcut Alt+Left to activate the back-button.
See also: remove_accelerator()