• 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: converting a characer to a keycode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: converting a characer to a keycode


  • Subject: Re: converting a characer to a keycode
  • From: "email@hidden" <email@hidden>
  • Date: Mon, 11 May 2009 09:59:40 -0700

At 9:27 AM +0200 5/11/09, Jean-Daniel Dupas wrote:
Le 9 mai 09 à 22:29, email@hidden a écrit :

At 9:14 PM -0700 5/8/09, email@hidden wrote:
ken wrote:

the only way i can think to perform this conversion is to itereate over the virtual key codes 0-127 (with various combinations of shift and option keys) until i find the one that matches the user input character.

and while this is certainly doable, it feels awfully clumsy (and
potentially slow).

is there a better way?


Create the inverse mapping once, e.g. in an NSDictionary, then use that mapping thereafter, instead of searching repeatedly.

This assumes there is an unambiguous inverse mapping, which ain't necessarily so. For example, a keyboard with a numpad has duplicate key legends for all numpad keys. I think these numpad keys have different keycodes than the keys in the main alphanum layout. So given a character like "1" (or "*", "=", etc.) it's not possible to
reverse it to a single unique keycode.

greg,
thanx for the reply. and yes i am aware of the possible duplicates. i was just hoping for a better way other that iterating via UCKeyTranslate (which turns out to be fast enough, so probably no need to cache via a dictionary or otherwise).

An alternative would be to parse the UCHR resource yourself instead of using UCKeyTranslate.


http://developer.apple.com/documentation/Carbon/reference/Unicode_Utilities_Ref/uu_app_uchr/uu_app_uchr.html

i actually thought about doing that... but since it was easiest to just use UCKeyTranslate (i had pre-existing code i could easily copy, paste, modify) to get my surrounding code working, i went with that initially with the intent to explore other solutions if performance was an issue. performance wasn't/isn't an issue, so i've left the simple approach in.


thanx for the suggestion.

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


References: 
 >Re: converting a characer to a keycode (From: "email@hidden" <email@hidden>)
 >Re: converting a characer to a keycode (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Re: Help debugging bindings issues
  • Next by Date: Creating NSAttributedString objects using WebKit in secondary thread
  • Previous by thread: Re: converting a characer to a keycode
  • Next by thread: Make an attributed string all uppercase without losing attributes?
  • Index(es):
    • Date
    • Thread