7.1 Overview

Accelerator class can be used to set up global keyboard shortcuts for a window. Normal keyboard shortcuts defined by using the underscore character are handled automatically by RapaGUI. See Keyboard shortcuts for details. However, sometimes you might want to use more complex keyboard shortcuts, e.g. you might want to listen to the escape key, function keys, certain control keys or key combinations (e.g. CTRL+V for paste). This is possible by using Accelerator class.

Accelerator class allows you to set up a table of keyboard shortcuts which can then be assigned to a window by using the Window.Accelerator attribute to make those shortcuts globally available in the respective window. Each accelerator table must contain at least one child of type Acceleratoritem class defining a single shortcut.

Here is an example of how to set up an accelerator table in XML:

 
<accelerator>
   <item id="ac_cut" mod="ctrl">X</item>
   <item id="ac_copy" mod="ctrl">C</item>
   <item id="ac_paste" mod="ctrl">V</item>
   <item id="ac_f1">F1</item>
</accelerator>

The accelerator table declared above sets up four different shortcuts: CTRL+X, CTRL+C, CTRL+V and F1. Whenever the user presses such a key or key combination, the Acceleratoritem.Pressed notification will be triggered and your application can then react on it.

Note that if you intend to link your accelerator items to menu items, you don't have to use Accelerator class at all. In that case you can just use the Menuitem.Shortcut attribute to set up shortcuts for your menu items. Accelerator class is really only necessary if you need to listen to keyboard events without having any menu items involved.

Accelerator class doesn't define any attributes or methods itself. See Acceleratoritem class for all necessary information.


Show TOC