Skip navigation.
 
mlRe: Map key codes to characters
FROM : Peter Edberg
DATE : Sat Feb 23 19:29:01 2008

Christian,
The mapping from a sequence of key codes to a sequence of UniChars 
(UTF16 code units, for the modern APIs) can be complex and in general 
is a state machine in which the inputs include keycode, modifier 
state, dead key state, and physical keyboard ID, and the outputs are 
updated dead key state and a sequence of 0 or more characters. The API 
that performs this mapping of keycode sequences to character sequences 
is UCKeyTranslate (in the CarbonCore framework in the CoreServices 
umbrella).

Consider the following simple sequence of keycode-modifier 
combinations on a US key layout (assuming an ANSI or ISO physical 
keyboard layout and assuming that dead key state is correctly 
maintained from one UCKeyTranslate  call to the next):

kVK_ANSI_E (0x0E) + option => no character output
kVK_ANSI_E (0x0E) + shift => 1 UniChar output: 0x00C9
kVK_ANSI_E (0x0E) + option => no character output
kVK_ANSI_X (0x07) + no modifiers => 2 UniChars output: 0x00B4 0x0078

In general there is no simple mapping from a given UniChar back to a 
single keycode. Consider UniChar 0x00B4 above, or perhaps even 0x9053, 
which requires interaction with an input method to produce.

Peter Edberg


On Feb 21, 2008, at 1:50 PM, <email_removed> wrote:

> ------------------------------
>
> Message: 14
> Date: Thu, 21 Feb 2008 22:48:15 +0100
> From: <email_removed> (Christian Schmitz)
> Subject: Map key codes to characters
>
> is there a modern API which I can use to map between keys
>
> For example giving 12 and want to get a "Q" back and for providing 
> "Q" I
> get a 12 back.
>
> Of course it would be nice to know the option keys.
>
> Is that possible?
>
> Currently I use iGetKeys, but that is failing for a lot of cases.

Related mailsAuthorDate
mlMap key codes to characters applelists Feb 21, 22:48
mlRe: Map key codes to characters Nick Zitzmann Feb 21, 22:57
mlRe: Map key codes to characters Andrew Farmer Feb 21, 23:17
mlRe: Map key codes to characters Peter Edberg Feb 23, 19:29