arkon
arkon

Reputation: 2296

Understanding C++ VK_ hotkey combination values

I've been playing around with the IShellLink interface, and am confused about how hotkey combinations are mapped.

When only single hotkeys are applied, the return value corresponds to the documented virtual key code; e.g. F5 == 0x74

However, when a combination is used, an undocumented value is returned that I'm having trouble deciphering; e.g. CTRL + ALT + A == 0x641

What operation is used to combine multiple virtual key codes?

Upvotes: 2

Views: 3673

Answers (2)

David Heffernan
David Heffernan

Reputation: 613262

This is explained in the documentation for IShellLink::GetHotkey:

The virtual key code is in the low-order byte, and the modifier flags are in the high-order byte. The modifier flags can be a combination of the following values:

  • HOTKEYF_ALT (ALT key)
  • HOTKEYF_CONTROL (CTRL key)
  • HOTKEYF_EXT (Extended key)
  • HOTKEYF_SHIFT (SHIFT key)

These flags are defined so:

#define HOTKEYF_SHIFT           0x01
#define HOTKEYF_CONTROL         0x02
#define HOTKEYF_ALT             0x04
#define HOTKEYF_EXT             0x08

So, when you take the CTRL and ALT flags to the high order byte of a word, and combine them, you get 0x0200 | 0x0400 which equals 0x0600. Combine this with the virtual key code for A which is 0x41 and you have your magic constant of 0x0641.

Upvotes: 6

Anders
Anders

Reputation: 101746

From IShellLink::GetHotkey on MSDN:

The address of the keyboard shortcut. The virtual key code is in the low-order byte, and the modifier flags are in the high-order byte. The modifier flags can be a combination of the following values.

HOTKEYF_ALT

HOTKEYF_CONTROL

HOTKEYF_EXT

HOTKEYF_SHIFT

You can use the traditional LOBYTE, HIBYTE and MAKEWORD macros to read/write...

Upvotes: 1

Related Questions