Map key codes to characters

  • Hi,

    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.

    Gruß
    Christian
  • On Feb 21, 2008 AD, at 2:48 PM, Christian Schmitz wrote:

    > 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.

    The only one is GetKeys(), but the output from GetKeys() is different
    on every architecture. Maybe that's what's causing the problem?

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • On 21 Feb 08, at 13:57, Nick Zitzmann wrote:
    > On Feb 21, 2008 AD, at 2:48 PM, Christian Schmitz wrote:
    >> 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.
    >
    > The only one is GetKeys(), but the output from GetKeys() is
    > different on every architecture. Maybe that's what's causing the
    > problem?

    GetKeys() works the same on PPC and Intel, so long as you interpret
    the results correctly. That being said, what it returns to you is
    literally just a bitmask representing the keys being pressed. If you
    want to map this into characters, matters get a lot more complicated
    (particularly if you consider that 'é' is a multi-key composite).

    What'd probably work better is if you explain what your goal is. Are
    you trying to represent a keystroke combination, or are you trying to
    take text input? The two take rather different approaches.
  • 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, <cocoa-dev-request...> wrote:

    > ------------------------------
    >
    > Message: 14
    > Date: Thu, 21 Feb 2008 22:48:15 +0100
    > From: <applelists...> (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.
previous month february 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29    
Go to today
MindNode
MindNode offered a free license !