I am considering creating a custom keyboard layout. The keys are mapped to unicode. One kind of shortcut that I often use is the alt + <arrow>
or alt + <backspace>
. How can I get the same effect with a unicode?

- 99
- 1
2 Answers
You can't. Unicode is a standard that describes characters, not keys. There's not even a Unicode code point for the F1 key, let alone for combinations.

- 173,980
- 10
- 155
- 350
-
You can define a right arrow, the behaviour associated is to move to the right. Why wouldn't be possible to move one word to the right? – asiegf Mar 24 '17 at 07:55
-
You can define a right arrow keystroke, but not as a unicode character. There _is_ a unicode right arrow, → (U+2191) but that is an actual printed character. – MSalters Mar 24 '17 at 08:49
The keys are mapped to unicode.
This statement is untrue. Keys are mapped to scancodes. Any mapping to a character set is performed by the OS and not all keys or key combinations necessarily map to a character either. An OS may further abstract key codes into virtual key codes in order to handle the wide variety of keyboard layouts and special keys.
Scancodes are 8-bit values with extended keys producing a code pair - the first being zero (NUL) indicating that a second code follows, thus allowing 510 distinct codes.
Note that the scancode generally applies to the specific key, not the character generated. For "character" keys, shift, alt, ctrl etc. (which have their own distinct scancodes) do not modify the scancode, so "extended" keys such as the functon keys, they can act as modifiers.
Normally you would not access the keyboard at the scancode level, but rather use the OS's keyboard services to determine key states or character mapping. For example by scancode alone you cannot distinguish between N
and n
- the key state of either left-shift, right-shift, alt-gr and the current caps-lock toggle-state must be considered. Scancode access is primarily for keyboard drivers to deal with.
Higher level keyboard access is OS specific. In Windows for example there is an extensive API and framework for keyboard access. Of interest in this case perhaps are the toUnicode()
and toUnicodeEx()
functions that map virtual key codes to Unicode (where such a translation exists). However there is no translation for Alt+ AFAIK, In a GUI message loop, you will get a WM_SYSKEYDOWN
message with a VK_UP
, VK_DOWN
, VK_LEFT
or VK_RIGHT
parameter. In fact you will get other messages, but WM_SYSKEYDOWN
is specifically issued for Alt+ sequences so you need not separately process and maintain state for the Alt key WM_KEYDOWN
/WM_KEYUP
.

- 88,407
- 13
- 85
- 165
-
Thank you for this answer, it has given me some insights. I still don't get why it is possible to have the behaviour of moving right with an arrow but there is no way you can make it move one word forward. – asiegf Mar 24 '17 at 07:59
-
@asiegfried : That's a very different question, not related to keyboard encoding but rather application behaviour. Most applications move the cursor by whole words using ctrl+
- that is default behaviour for most standard text edit widgets on most platforms AFAIK - so you probably don't need to code support specifically. In Windows at least ALT+ sequences are frequently assigned to "hot keys" and system behaviour and should probably be avoided. – Clifford Mar 24 '17 at 13:27