Re: keyCode translation for various keyboards
Re: keyCode translation for various keyboards
- Subject: Re: keyCode translation for various keyboards
- From: Dave Carpeneto <email@hidden>
- Date: Wed, 03 Feb 2010 00:46:27 -0500
Dave Carpeneto wrote:
Hello list folk - I'm trying to print out strings representing various
keyDown events I receive. Using OS 10.6.2.
...
So far the two approaches I've seen are as follows:
...
Approach #2: Get what you can via UCKeyTranslate, and then 'fill in
the blanks' with a lookup table for non-alphanumeric stuff (example:
http://inquisitivecocoa.com/2009/04/05/key-code-translator , which
looks like it builds off a patched version of
http://rogueamoeba.com/sources/HotKeysLib3.zip )
Prior threads by people in the know (
http://www.cocoabuilder.com/archive/cocoa/101991-key-codes-and-characters-in-nsevents.html
) further state that developer-created lookups are a fact of life in
this area, but I'm reely hoping they are not ...
OK, given that even the up-to-date code snippets I can find on the
interwebs ( http://code.google.com/p/shortcutrecorder ) do the lookup
thing I'm guessing that there's no better way to go about it. Which is a
shame, as I'm still freaked out about the possibilities that
international keyboards may present. But at least I'm pretty confident
this is what everyone else is doing, so "as bad as everyone else" is
good enough I guess ;-)
On the off chance that someone else bangs their head against this
situation here's the mapping table I've come up with, which gives pretty
unicode symbols where possible:
// keycode mappings from http://ritter.ist.psu.edu/projects/RUI/macosx/rui.c
// unicode symbols from
https://wincent.com/wiki/Unicode_representations_of_modifier_keys
// more unicode @
http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/KEYBOARD.TXT
keyCodeToStringDict = [[NSDictionary alloc] initWithObjectsAndKeys:
@"\u23CE", [NSNumber numberWithInteger: 36], // Ret
@"\u21E5", [NSNumber numberWithInteger: 48], // Tab
@"\u2423", [NSNumber numberWithInteger: 49], // Space
@"\u232B", [NSNumber numberWithInteger: 51], // <-Del
@"\u2324", [NSNumber numberWithInteger: 52], // Enter
@"\u238B", [NSNumber numberWithInteger: 53], // Esc
@"\u2327", [NSNumber numberWithInteger: 71], // Clear
@"\u2324", [NSNumber numberWithInteger: 76], // Enter
@"\uF860F1", [NSNumber numberWithInteger:122], // F1
@"\uF860F2", [NSNumber numberWithInteger:120], // F2
@"\uF860F3", [NSNumber numberWithInteger: 99], // F3
@"\uF860F4", [NSNumber numberWithInteger:118], // F4
@"\uF860F5", [NSNumber numberWithInteger: 96], // F5
@"\uF860F6", [NSNumber numberWithInteger: 97], // F6
@"\uF860F7", [NSNumber numberWithInteger: 98], // F7
@"\uF860F8", [NSNumber numberWithInteger:100], // F8
@"\uF860F9", [NSNumber numberWithInteger:101], // F9
@"\uF861F10",[NSNumber numberWithInteger:109], // F10
@"\uF861F11",[NSNumber numberWithInteger:103], // F11
@"\uF861F12",[NSNumber numberWithInteger:111], // F12
@"\uF861F13",[NSNumber numberWithInteger:105], // F13
@"\uF861F14",[NSNumber numberWithInteger:107], // F14
@"\uF861F15",[NSNumber numberWithInteger:113], // F15
@"\uF861F16",[NSNumber numberWithInteger:106], // F16
@"\uF861F17",[NSNumber numberWithInteger: 64], // F17
@"\uF861F18",[NSNumber numberWithInteger: 79], // F18
@"\uF861F19",[NSNumber numberWithInteger: 80], // F19
@"?\u20DD", [NSNumber numberWithInteger:114], // Help
@"\u21F1", [NSNumber numberWithInteger:115], // Home
@"\u21DE", [NSNumber numberWithInteger:116], // PgUp
@"\u2326", [NSNumber numberWithInteger:117], // Del->
@"\u21F2", [NSNumber numberWithInteger:119], // End
@"\u21DF", [NSNumber numberWithInteger:121], // PgDn
@"\u2191", [NSNumber numberWithInteger:126], // Up
@"\u2193", [NSNumber numberWithInteger:125], // Down
@"\u2190", [NSNumber numberWithInteger:123], // Left
@"\u2192", [NSNumber numberWithInteger:124], // Right
nil];
Questions:
1) Is there a programmatic method to get strings like this (I'm
guessing not)
2) Is a F1 key the same on all keyboards (if so then my worries
about the lookup table are a non-issue)
3) Are there any keys typical in other places that don't exist on a
'standard' North American keyboard ? (if so heaven help me)
Thanks all for any insight you may be able to provide - Dave
_______________________________________________
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