3.10 Keyboard shortcuts

RapaGUI allows you to set up keyboard shortcuts really easily by simply using an underscore character ("_") before the character you would like to set up as a keyboard shortcut. You should always provide support for keyboard shortcuts because many users prefer to use them instead of the mouse, especially when it comes to actions which have to be repeated dozens of times it is much easier to use the keyboard instead of, just as an instance, having to navigate to certain submenus hidden deep within the menu hierarchy all the time. The following classes support keyboard shortcuts defined through the underscore character:

Here is an example of how to set up two keyboard shortcuts for widgets derived from Button class:

 
<hgroup>
   <button>_OK</button>
   <button>_Cancel</button>
</hgroup>

The XML code above will set up "O" and "C" as keyboard shortcuts. On Windows, the user has to press ALT+O to select the "OK" button and ALT+C to select the "Cancel" button. On other platforms the combinations are sometimes different, e.g. on Mac OS you have to use the COMMAND key instead of the ALT key.

Since Label class doesn't create widgets that can be controlled by the user, specifying a keyboard shortcut for labels simply activates the next widget in the GUI layout, which is usually the widget that is described by the label. For example:

 
<hgroup>
   <label>_Name</label>
   <textentry/>
</hgroup>

As you can see, in the XML code above "N" has been set up as a keyboard shortcut by using an underscore character. Pressing ALT+N will activate the text entry widget then since label widgets cannot take the window focus.

In the rare case that you want to use the underscore character as a label text for one of your widgets and not have it automatically converted into a token indicating a keyboard shortcut, you can just set the Area.NoAutoKey attribute to True. If this is set, RapaGUI will simply show the underscore character and won't treat it as a special token. Note: Since menu and menuitem objects aren't derived from Area class, you need to use Menu.NoAutoKey and Menuitem.NoAutoKey in case you want to disable automatic shortcut generation for menu or menuitem objects.

If you need to use more complex keyboard shortcuts (e.g. certain function or control keys, combinations of keys), you have to set up an accelerator table using Accelerator class for your window. Accelerator class allows the definition of advanced keyboard shortcuts which are also independent of any widgets in your window. If your complex keyboard shortcuts are linked to menu items, however, you don't have to use Accelerator class but you can just set the Menuitem.Shortcut attribute to the desired shortcut. This will automatically set up an accelerator then. See Menuitem.Shortcut for details. See Accelerator class for details.


Show TOC