Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between hotkey, shortcut and accelerator key?

Tags:

c++

windows

qt

  1. What is the difference about them?

  2. In Qt, if I have a hotkey for QPushButton, I can make it by "Alt + ?", but if it's for qaction, I can press "?" only

like image 958
user1318674 Avatar asked Apr 16 '12 05:04

user1318674


People also ask

What is key accelerator?

Accelerator keys (or keyboard accelerators) are keyboard shortcuts that improve the usability and accessibility of your Windows applications by providing an intuitive way for users to invoke common actions or commands without navigating the app UI.

What is the hotkey?

A hot key is a key or a combination of keys on a computer keyboard that, when pressed at one time, performs a task (such as starting an application) more quickly than by using a mouse or other input device. Hot keys are sometimes called shortcut keys. Hot keys are supported by many operating system and applications.

How do I use the accelerator key?

Accelerator keys enable the user to access a menu command from the keyboard by pressing Alt+ the appropriate letter, indicated in your code by the preceding ampersand. The letter after the ampersand appears underlined in the menu.


3 Answers

In Windows, an accelerator key is application global; e.g. Alt+F4.

A shortcut key is part of the name of a menu item or button, where it can be underlined, and is available (without modifiers) when that menu item or button is directly available.

From Microsoft:

A hot key is a key combination that the user can press to perform an action quickly. For example, a user can create a hot key that activates a given window and brings it to the top of the z-order.

which seems to indicate that hot keys are system global.

To sum up:

  • shortcut key = no modifiers, local in menu or (for button) in window
  • accelerator key = typically with modifier, application global
  • hot key = apparently system global

I don't know about specific meanings in Qt; for that see the Qt documentation.

like image 200
Cheers and hth. - Alf Avatar answered Sep 30 '22 11:09

Cheers and hth. - Alf


Alf's answer is correct for Windows applicability. Your terms you mention (hotkey/shortcut/accelerator) don't sound familiar from a pure Qt point of view.

In Qt you can elect to handle key sequences yourself or you can use Qt's own simplification method. Either way you must remember that Qt itself targets many platforms on which a key combination may or may not make sense. The classic Alt + F4 makes sense on a keyboard, but on a mobile device you don't have an Alt modifier or an F4 key. What you really want is a way of specifying a generic close the application shortcut. This problem is multiplied because the symbol may be available but the key sequence to reach it might be different on other keyboard layouts. This section of the documentation provides a good example.

Qt handles this with class QKeySequence. The very clever Qt developers have provided an easy way of defining common user actions and those actions will use key combinations that are default to the target platform. It does this using enum QKeySequence::StandardKey and in the close the application example, you could use this like so:

QAction exitAction; exitAction.setShortcut(QKeySequence(QKeySequence::Quit)); 

This is all explained in the documentation. There are a two other modifiers (shortcutContext() and softKeyRole()) which can be applied to QActions which effect their application in more advanced ways.

You are also free to assign your own shortcuts using something like:

QAction helpAction(tr("&?")); helpAction.setShortcut(QKeySequence(tr("ALT+?"))); 

The first line applies the (translated) text "?" to the action which will appear as its text on a menu or button. Note that the question mark symbol might not be the right symbol in all languages so the translate method allows a translator to assign a more appropriate symbol if required. The ampersand symbol means the character immediately after will be the short-cut key when the menu is active.

The second line assigns the (translated) shortcut of Alt + ? and in this example the Shift modifier will be handled by the platform if required. Again, the tr() method allows the translator to specify a more appropriate shortcut if available.


In response to teukkam's comment:

If you mean you simply want your button to be triggerable by a keystroke whether its modified by Alt or not then you could do something like:

QPushButton* yourButton; // assign this pointer yourself yourButton->setText(tr("&Process")); yourButton->setShortcut(tr("p")); 

In this example, the ampersand in setText() does the same as the previous example, and the translate function is used in the same way.

The setShortcut() method just uses the letter "p" so should work now with or without the Alt modifier. A quick skim of the documentation suggests this will work with or without the Shift modifier as the letters in a key sequence are apparently case-insensitive.

Also, P would be a bad choice as its often assumed to be the print command.

A final note if you're defining hard coded short cuts, make sure they work on all your target platforms!

like image 36
Samuel Harmer Avatar answered Sep 30 '22 11:09

Samuel Harmer


In Windows:

HotKey

Keyboard key or combination of keys that execute a command in a given context.

Shortcut

Multi-key HotKey with no menu navigation restrictions nor gui elements required.

AccessKey

Single key HotKey which command is to activate a visible command control (requires gui element) that is captioned/labeled with the corresponding hotkey letter underscored.

Accelerator Keys

Multi-key HotKey which command is to activate a command control (requires gui element) regardless of its visibility.

like image 37
Jorge Picco Avatar answered Sep 30 '22 10:09

Jorge Picco