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 PROTECTED] wrote:

------------------------------

Message: 14
Date: Thu, 21 Feb 2008 22:48:15 +0100
From: [EMAIL PROTECTED] (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.

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to