Next: Preferences support in custom files, Previous: Adding tool bar buttons, Up: Customizing through XML and Python files

#### 16.5.8 Binding actions to keys

All the actions defined above can be bound to specific key shortcuts through the `<key>` attribute. As usual, it requires one `<action>` attribute to specify what to do when the key is pressed. The name of the action can start with a '/' to indicate that a menu should be executed instead of a user-defined action.

If the action is the empty string, then instead the key will no longer be bound to any action.

This tag doesn't contain any child tag. Instead, its text contents specified the keyboard shortcut. The name of the key can be prefixed by `control-`, `alt-`, `shift-` or any combination of these to specify the key modifiers to apply.

You can also define multiple key bindings similar to Emacs's by separating them by a space. For instance, `control-x control-k` means that the user should press <control-x>, followed by a <control-k> to activate the corresponding action. This is only possible if the prefix key is not already bound to an action. If it is, you should first unbound it by passing an empty action to `<key>`.

Use an empty string to describe the key binding if you wish to deactivate a preexisting binding. The second example below deactivates the standard binding.

         <?xml version="1.0" ?>
         <keys>
           <key action="expand alias">control-o</key>
           <key action="Jump to matching delimiter" />

           <!--  Bind a key to a menu -->
           <key action="/Window/Close">control-x control-w</key>
         </key>

Multiple actions can be bound to the same key binding. They will all be executed in turn, followed by any menu for which this key is an accelerator.

When GPS processes a `<key>` tag, it does the following:

- Removes all actions bound to that key. This ensures that if you press the key, any action associated with it by default in GPS or in some other XML file will no longer be executed, and only the last one will be executed.
- Adds the new key to the list of shortcuts that can execute the action. Any existing shortcut on the action is preserved, and therefore there are multiple possible shortcuts for this action.