Re: -charactersIgnoringModifiers and the shift key
Re: -charactersIgnoringModifiers and the shift key
- Subject: Re: -charactersIgnoringModifiers and the shift key
- From: "Hank Heijink (Mailinglists)" <email@hidden>
- Date: Thu, 17 Apr 2008 13:11:10 -0400
I assume you picked cmd-shift-[ because the curly brace makes sense,
in which case you really are looking for cmd-{. If someone has a
keyboard where the shifted version of [ is @ (no idea if such a
keyboard actually exists), you might not want your shortcut to be cmd-
shift-[.
So, I think you'd be best off coding your hotkey as cmd+{. On an
international keyboard, there's not telling what shift-[ could be, and
it's even possible that [ is the shifted version of another character.
I'd go for the actual character and its meaning, not the key.
Best,
Hank
On Apr 17, 2008, at 12:02 PM, 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:
@runbox.com
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