An accelerator table allows the application to specify a table of keyboard shortcuts for menus or other commands. On Windows, menu or button commands are supported; on GTK (and OS X?), only menu commands are supported.
A window initially has no accelerator table entries, although menus associated with frames may have shortcut keys for their entries.
This example shows how to create an accelerator table with three shortcut key entries. Each entry specifies:
acc_table = Wx::AcceleratorTable[
[ Wx::MOD_CONTROL, ?n, ID_NEW_WINDOW ],
[ Wx::MOD_ALT, ?x, Wx::ID_EXIT ],
[ Wx::MOD_SHIFT, Wx::K_DELETE, Wx::ID_CUT] ]
frame.accelerator_table = acc_table
Note that in ruby 1.8, using the ?x notation is an easy way to retrieve
the integer value of the character “x”. For ruby 1.9, you must use "x".ord instead
as ?x returns the character “x” and not its integer value.
To use keys with special characters that can’t be typed, such as “Delete”, use wxRuby’s
Wx::K_XXX key code constants.
Any of wxRuby’s modifier keys may be used to refine an
entry. For portability between OS X and GTK and Windows, it may be
preferable to use the Wx::MOD_CMD modifier instead of
Wx::MOD_CONTROL. This will map to “keypress + APPLE” on OS X – the
normal modifier for shortcuts, but “keypress + CTRL” on GTK and
Windows.
Accelerator modifiers may also be used instead (Wx::ACCEL_ALT, Wx::ACCEL_SHIFT, Wx::ACCEL_CTRL and Wx::ACCEL_NORMAL).
Using the events from this accelerator table, the corresponding event handler declaration to catch the first of these would look like:
evt_menu(ID_NEW_WINDOW) { .... }
An accelerator takes precedence over normal processing and can be a convenient way to program some event handling. For example, you can use an accelerator table to enable a dialog with a multi-line text control to accept CTRL-Enter as meaning `OK’ (but not in GTK+ at present).
AcceleratorEntry, Window#set_accelerator_table
AcceleratorTable[Object entries]
AcceleratorTable.new(Object entries)
Creates a new accelerator table from the single entry or the array of entries. An entry is defined as an AcceleratorEntry object, or for convenience, as a three-element array representing the modifiers, the key, and the event id in turn.
Boolean is_ok()
Returns true if the accelerator table is valid.
[This page automatically generated from the Textile source at Fri Feb 27 23:38:50 +0000 2009]