Re: -charactersIgnoringModifiers and the shift key
Re: -charactersIgnoringModifiers and the shift key
- Subject: Re: -charactersIgnoringModifiers and the shift key
- From: John Stiles <email@hidden>
- Date: Thu, 17 Apr 2008 09:38:19 -0700
Quick question: in Leopard, are there any keyboards left which don't
have a uchr?
I found some sample code which includes a fallback case for if no 'uchr'
resource is found (it uses plain KeyTranslate in this case) and I'm
wondering whether this is still relevant in the Leopard-and-above timeframe.
John Stiles wrote:
Sweet, I will take a look at this and post back when I have results or
questions. Thanks!
Greg Titus wrote:
I think you'd ask the NSEvent for its -keyCode, then pass that key
code to UCKeyTranslate() with all the modifier key state (including
shift) turned off in order to get a unicode string for what that key
would mean if the user hadn't been pressing any modifiers.
Hope that helps,
- Greg
On Apr 17, 2008, at 9:02 AM, John Stiles wrote:
I have an NSEvent and I need to know what key the user has pressed,
minus any of the modifiers. NSEvent -charactersIgnoringModifiers
seems like a good place to start, but it has one serious flaw—it
does not ignore the Shift key. So, for instance, it won't change ~
to `, ! to 1 or { to [.
I need this for my app, because I am trying to implement
functionality where the user can add custom hotkeys to buttons or
menu items—this is a requirement of the design, it works well
conceptually, and it works well on the Windows side. On the Mac
side, however, there are lots of problems where AppKit will get
confused when two items have similar hotkeys (such as rdar://5848023
[NSResponder] Problem with button hotkeys and shift modifier, which
I posted about here before) and the end result is that it, with some
key combinations, AppKit sends the action message to the wrong menu
item or button.
To work around these issues, when the user presses a hotkey, I am
looking at [NSApp currentEvent] to see what key is actually pressed,
and given that info I can easily figure out what button or menu item
needs to be invoked on my own. To do this, I use [event
charactersIgnoringModifiers] and [event modifierFlags] and then
checking a dictionary of all the hotkeys. For most things, this
works well. Where it falls down is shifted punctuation, because my
dictionary has the hotkey listed as "cmd+shift+[", but the event is
telling me that the user pressed "cmd+shift+{". Of course,
"cmd+shift+{" isn't in my table at all, so it doesn't work.
I could bite the bullet and hard-code the unshifted versions of all
the keys on the US keyboard, and that would make Americans happy,
but I expect we will eventually need to "do the right thing" so I
need to actually get the unshifted character out of this NSEvent. So
how can this be done? Any pointers would be helpful.
_______________________________________________
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
_______________________________________________
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
_______________________________________________
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