Re: Getting a NSMenuItem to respond to two different key equivalents
Re: Getting a NSMenuItem to respond to two different key equivalents
- Subject: Re: Getting a NSMenuItem to respond to two different key equivalents
- From: Adam Knight <email@hidden>
- Date: Fri, 12 Oct 2007 09:22:21 -0500
For the sake of the archives, here's what worked (thanks!). I added
the following to a NSApplication subclass and updated my Info.plist
accordingly (note characters and charactersIgnoringModifiers):
- (void)sendEvent:(NSEvent *) event
{
if ([event type] == NSKeyDown) {
if( (([event modifierFlags] & NSCommandKeyMask) ==
NSCommandKeyMask) && [[event charactersIgnoringModifiers]
isEqualToString:@"="] ) {
event = [NSEvent keyEventWithType:[event type] location:[event
locationInWindow] modifierFlags:[event modifierFlags] timestamp:
[event timestamp] windowNumber:[event windowNumber] context:[event
context] characters:@"=" charactersIgnoringModifiers:@"+" isARepeat:
[event isARepeat] keyCode:[event keyCode]];
}
}
[super sendEvent:event];
}
Adam Knight
Notae: Organize your notes, organize your life - http://
www.codepoetry.net/products/notae/
On Oct 11, 2007, at 5:34 PM, Benjamin Stiglitz wrote:
The NIBs are *not* using the nifty alternate item feature because
you can't do that with only shift, it seems (can't even check it
off in IB). I tried mangling in validateMenuItem but that's not
called unless the menu is being displayed, it seems. So where can
I flip the keyEquivalent as this happens, if that's what's
happening (the simplest solution).
You can check for the alternate in -[NSApplication sendEvent:] and
call super with a synthetic event whose characters are changed to
match the equivalent on the menu item. That has the benefit of
invoking all the standard mechanisms for matching key equivalents
and highlighting the menu item.
-Ben
_______________________________________________
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