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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to