Keyboard Table of Contents | Keyboard Index |
The key map records character values using the UTF-8 encoding of the Unicode Standard, making it possible to map keys to characters in any of the world's scripts. UTF-8 encodes 16-bit Unicode values in a variable number of bytes (from one to four). The main benefit to UTF-8 is that one-byte UTF characters $00 through $7F are identical to the ASCII standard that's been around for decades.
A B_KEY_DOWN message holds the character mapped to the key the user pressed as an array of bytes named, simply, "byte". The array is passed as a string to the KeyDown() hook function along with a count of the number of bytes in the string:
See "Character Encoding" in the "Responding to the User" section of the Interface Kit for a description of UTF-8 encoding and get_key_map() for an explanation of the key map.
Most keys are mapped to more than one character. The precise character that the key produces depends on which modifier keys are being held down and which lock states the keyboard is in at the time the key is pressed.
A few examples are given in the table below:
Key | No modifiers | Shift alone | Option alone | Shift & Option | Control |
---|---|---|---|---|---|
0x15 | 4 | $ | 4 | ||
0x18 | 7 | & | xa6 | xa4 | 7 |
0x26 | B_TAB | B_TAB | B_TAB | B_TAB | B_TAB |
0x2e | i | I | B_TAB | ||
0x40 | g | G | " | 0x07 | |
0x43 | k | K | B_PAGE_UP | ||
0x51 | n | N | ñ | Ñ | 0x0e |
0x55 | / | ? | xb8 | xc0 | / |
0x64 | B_INSERT | 0 | B_INSERT | 0 | B_INSERT |
The mapping follows some fixed rules, including these:
The default key map also follows the conventional rules for Caps Lock and Control:
However, if the lock doesn't affect the character, Shift plus the lock is the same as Shift alone. For example, Caps Lock-7 produces '7' (the lock is ignored) and Shift7 produces '&' (Shift has an effect), so Shift-Caps Lock-7 also produces '&' (only Shift has an effect).
When Control is used with a key that doesn't produce an alphabetic character, the character that's reported is the same as if no modifiers were on. For example, Control7 produces a '7'.
Keyboard Table of Contents | Keyboard Index |
Copyright © 2000 Be, Inc. All rights reserved..