Design and Layout:Controls:Shortcuts

From KDE-HIG_Wiki


Shortcuts and Accelerators

Keyboard Shortcuts

A keyboard shortcut is a combination of keystroke combinations that starts a command from the menu. It consists of one or more modifier and a character key, e.g. Ctrl+C. Unlike accelerators, keyboard shortcuts do not post menus but perform the action directly.

The keyboard shortcuts are displayed next to their corresponding item in the menu so that the user can learn about the shortcuts by using the application.

Note that the shortcut keys are not subject to translation. The shortcut for File->Open will be Ctrl+O in all languages, even if the menu item does not contain an O in one language.


Guidelines

Selecting the right actions

  • Assign shortcuts to the application's most commonly-used actions only.
  • Define keyboard shortcuts application-wide.
    • If the action is not supported within a certain context, no action will be taken.
    • If a shortcut supports different actions in a local and a general context (see e.g. volume versus tab navigation in section keyboard navigation), the local context has priority over the general context when the local context is focused.


Defining keyboard shortcuts

  • Provide the standard shortcuts for common actions (see Standard Keyboard Shortcuts).
  • Don't use any of the standard shortcuts for any other purposes - even if the standard action is not supported by your application.
  • Use Ctrl+character in preference to other combinations for your application-specific shortcuts.
  • Don't use the Alt key without another modifier key for keyboard shortcuts as these may conflict with window manager or menu access keys.
  • Functions that reverse another function should be indicated by Ctrl+Shift+character.
    For example, Ctrl+A and Ctrl+Shift+A for Select All and Deselect All.
  • Don't use symbols that require Shift or other modifiers as part of the shortcut, for example Ctrl+%. It may cause problems as symbols are accessed differently on international keyboards.
  • Make your shortcuts as mnemonic as possible to facilitate learning and remembering.
    For example, Ctrl+I would be a good shortcut for a menu item called Indent.


Implementation Notes

Caution: Shortcuts and accelerators are often mixed up because Qt™ and KDE use the QAccel and KAccel classes to define shortcuts, but no special classes are needed to define accelerators (see section Keyboard Accelerators).

Do not hardcode shortcut keys — use the KStdAccel and its related classes for defining them. That way, your application will stay consistent with other applications if the user decides to configure other keys as shortcut keys.


Keyboard Accelerators

An accelerator key provides another keyboard alternative to activate a menu or other interface elements. It is an alphanumeric key that must be pressed simultaneously with a Meta-key, usually Alt, to select an item which is visible on the screen. The accelerator key is marked by underlining the corresponding character in the menu title, the menu item, or in other interface components.

For example, to choose the Quit command from the File menu, the user has to hold the Alt key and F to post the File menu, and then press Q to quit the application.

Note that accelerator keys are subject to translation: a French menu will have different accelerators from those of an English menu.


Guidelines

General Guidelines

  • Provide accelerator keys for all features of an application.
  • Make sure the controls have labels, so accelerators can be applied. This also includes lists or tables.
  • Assign the most important accelerator keys manually to make sure they are meaningful.
  • It is recommended to check the automatically assigned accelerators for coherence (see next paragraph).


Defining accelerators manually

  • As far as possible, provide the standard accelerators for common actions (see Standard Keyboard Accelerators).
  • When defining application-specific accelerators, start with the most frequently used controls.
  • Assign the first letter of the label as the accelerator key, or of one of its other words if it has more than one. If another letter provides a better association (e.g. X in Export), consider using that instead.
  • If the first letter of the item conflicts with those of other items, choose a prominent consonant.
  • If the first letter of the menu item and the prominent consonant conflict with those of other menu items, choose a prominent vowel.
  • Check for collisions.


Implementation Notes

No special classes are needed to define accelerators. An accelerator is created automatically by QLabel. The developer or translator can specify which key to use as accelerator by preceding this character in the label text with an ampersand (&).

To assign accelerators to lists or tables, you have to link them with their label via Qt Designer's "Edit Buddy" function.