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[ ] frame.accelerator_table = acc_table
[ Wx::MOD_CTRL, Wx::K_DELETE, Wx::ID_CUT)Note that in ruby, using the ?x notation is an easy way to retrieve
the integer value of the character “x”. 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_CTRL. This will map to “keypress + APPLE” on OS X – the
normal modifier for shortcuts, but “keypress + CTRL” on GTK and
Windows.
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.new(AcceleratorEntry entries)
AcceleratorTable
Creates a new accelerator table from the list of entries. The entries may be passed in as AcceleratorEntry% objects, or for convenience, may be specified as three-element arrays, reprsenting 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 Thu Aug 28 20:29:03 +0100 2008]