After all, it’s called a hotkey, not a hotcharacter

A customer was writing a remote access program, and they were having trouble injecting hotkeys into the system.

We are sending the modified key as a scan code, and the base character as a Unicode character. We find that shortcuts of the form Modifier+Letter, such as Ctrl+A, are not working. Are there known limitations for keyboard shortcuts sent as a scancode+Unicode character?

We are sending the base character as a Unicode character to avoid issues with localization and keyboard layouts.

Keyboard shortcuts are based on virtual key codes, not Unicode characters. After all, it's called a hotkey, not a hotcharacter.

Continuing the above example, the Ctrl+A hotkey is not a Ctrl plus the Unicode character U+0041 (LATIN CAPITAL LETTER A).

You cannot hold the Ctrl key while typing Alt+0 Alt+6 Alt+5 on the numeric keypad to get a Ctrl+A.

Even if CapsLock is off, you don't have to hold the shift key to get a capital A.

For the hotkey Win+1, you have to press the 1 on the main keyboard, not on the numeric keypad, even if NumLock is on.

Keyboard hotkeys consist of the applicable modifiers, combined with the key on the keyboard that has the appropriate symbol printed on it. Sending a Unicode character isn't the same as simulating a press of a key on a keyboard.

You have to send the virtual key to complete the hotkey sequence.

Comments (7)
  1. kantos says:

    IIRC from what I remember of the dearly departed Michael Kaplan’s blog, keyboard layouts are implemented as kind of a lookup table the kernel uses to map the physical key to the virtual key, and then a map of that how the live keys and dead keys interact to create input.

    1. Azarien says:

      Speaking of layouts, it would be nice to have the ability to use different layouts on different physical keyboards…

  2. Aged .Net Guy says:

    So is that to say the customer’s hope “… to avoid issues with localization and keyboard layouts” is in vain? That the remote control (“master”) program must know which keyboard layout is in use on the remote (“slave”) session and do all the translation on the master end? Which leads to all sorts of fun if the master end doesn’t have the slave’s keyboard layout even installed, much less in use.

  3. Pierre B. says:

    Hotkeys are a mess.

    Some are hard-coded to letters, like Ctrl-C, which means pressing Ctrl and whichever key has ‘C’ on it.

    Other are linked to word, so it’s Ctrl-H (say) in one language, and Ctrl- in another. So it’s linked to localisation.

    Yet others are linked to positions on the keyboard (think WASD to move in a game). So you need to adjust to physical layout.

    Yet others are user-configurable… and then you need to know what the user meants. Is tilde (~) shift+backquote? Or tilde? Or Shift + whichever key happens to be below ESC?

    Good luck. It’s a mess of intentions, layout, localisation and mind reading.

  4. Kumar R says:

    Neither is it called a hotvirtualscancode. How should anyone assume it’s a scan code?

    1. smf says:

      Because it’s called a hotkey and keys are represented by scancodes.

      You press keys to get characters, but that doesn’t mean characters are keys.

Comments are closed.

Skip to main content