• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Get unmodified character for key matching
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get unmodified character for key matching


  • Subject: Re: Get unmodified character for key matching
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 27 Mar 2014 13:24:33 -0500

On Mar 27, 2014, at 12:55 PM, Mills, Steve wrote:

> Fixing one small correction in the first line:
>
> If I type command-shift-/, the OS sends '?' instead of '/' (edit: was '-') in the NSEvent's characters and charactersIgnoringModifiers properties when using an English keyboard. If using a German keyboard, typing command-shift-- will result in the NSEvent sending us '_' instead of '-'. How can I map the modified version of a character back to its unmodified character and have it be correct for keyboards of all languages?

If you want to know what key was pressed in a physical (or pseudo-physical) sense, you should pay attention to the keyCode of the NSEvent.  If you want to know what a given key code maps to with the user's current keyboard layout, you would use UCKeyTranslate() to translate from key code to character.  You specify the modifier keys which should affect translation, and for your purposes you'd specify none.

To get the 'uchr' data needed as input to UCKeyTranslate(), you can query TISCopyCurrentKeyboardLayoutInputSource() to get the keyboard layout input source, then TISGetInputSourceProperty() with key kTISPropertyUnicodeKeyLayoutData.

To get the keyboard type needed as input to UCKeyTranslate(), you can call the ancient (but still legal, as far as I know) LMGetKbdType() function.  If you prefer, you can get a CGEvent from the NSEvent, then CGEventCreateSourceFromEvent(), then CGEventSourceGetKeyboardType().

Cheers,
Ken


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Get unmodified character for key matching
      • From: "Mills, Steve" <email@hidden>
References: 
 >Get unmodified character for key matching (From: "Mills, Steve" <email@hidden>)
 >Re: Get unmodified character for key matching (From: "Mills, Steve" <email@hidden>)

  • Prev by Date: Re: Get unmodified character for key matching
  • Next by Date: Re: Get unmodified character for key matching
  • Previous by thread: Re: Get unmodified character for key matching
  • Next by thread: Re: Get unmodified character for key matching
  • Index(es):
    • Date
    • Thread