More On Keyboard Mapping

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:

virtual void KeyDown(const char* bytes, int32 numBytes)

See "Character Encoding" in the Interface Kit chapter 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:

KeyNo modifiersShift aloneOption aloneShift + OptionControl
0x154$  4
0x187&¦¤7
0x26B_TABB_TABB_TABB_TABB_TAB
0x2eiI  B_TAB
0x40gG" 0x07
0x43kK  B_PAGE_UP
0x51nNñÑ0x0e
0x55/?¸À/
0x64B_INSERT0B_INSERT0B_INSERT

The mapping follows some fixed rules, including these:

The default key map also follows the conventional rules for Caps Lock and Control:

Creative Commons License
Legal Notice
This work is licensed under a Creative Commons Attribution-Non commercial-No Derivative Works 3.0 License.