• 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
keyCode translation for various keyboards
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

keyCode translation for various keyboards


  • Subject: keyCode translation for various keyboards
  • From: Dave Carpeneto <email@hidden>
  • Date: Tue, 02 Feb 2010 17:46:11 -0500

Hello list folk - I'm trying to print out strings representing various keyDown events I receive. Using OS 10.6.2.

It looks as though this was possible back in the classic days ( http://developer.apple.com/legacy/mac/library/documentation/mac/Toolbox/Toolbox-78.html ), however obviously that doesn't do much for me here.

Obviously the characters / charactersIgnoringModifiers strings I get with the event works great for alphanumeric stuff, however I'm also interested in things like function keys & the like. And up to this point I'm afraid that all I've been able to find on this makes me think I'm going to have hard-code a lookup table to translate non-alphanumeric key presses, which has me freaked out, since I've no idea what keyboards are like in other locales.

So far the two approaches I've seen are as follows:

Approach #1: Map every keyCode you can think of (example: the keyStringForKeyCode method in http://ritter.ist.psu.edu/projects/RUI/macosx/rui.c ) :

   switch (keyCode) {
       case 0: return("a");
       case 1: return("s");
       ...
       case 96: return("F5");
       ...

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

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


  • Follow-Ups:
    • Re: keyCode translation for various keyboards
      • From: Dave Carpeneto <email@hidden>
  • Prev by Date: NSFont to CGFontRef
  • Next by Date: Re: NSFont to CGFontRef
  • Previous by thread: NSFont to CGFontRef
  • Next by thread: Re: keyCode translation for various keyboards
  • Index(es):
    • Date
    • Thread