• 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
[SOLUTION] Option-Key "alternative" application behavior == mnemonics?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLUTION] Option-Key "alternative" application behavior == mnemonics?


  • Subject: [SOLUTION] Option-Key "alternative" application behavior == mnemonics?
  • From: John Blackburn <email@hidden>
  • Date: Fri, 15 Mar 2002 11:05:10 -0800

My solution was to add a category to NSEvent, since alternate behavior is useful in a number of places:

@implementation NSEvent (EventCategory)
- (BOOL)optionKeyDown {
return ([self modifierFlags] & NSAlternateKeyMask) != 0;
}
@end

This made the option-key check simple:

if ([[myWindow currentEvent] optionKeyDown])
// alternate behavior
else
// standard behavior

John Blackburn


On Wednesday, March 13, 2002, at 05:31 PM, John Blackburn wrote:

Hello,

What's the usual way to handle Option-Key "alternative" application behavior? For example, when the user chooses the Move To Trash menu item (Command-Delete) in my application, I show a confirm sheet. I wish to bypass that sheet if the user's holding down the Option key (Command-Option-Delete).

This sounds like a job for performMnemonic:, but I can't figure out how to set the mnemonic for this behavior. I see the spot in IB where you set the keyboard equivalents, but that's just for the standard behavior. In this list's and Omni's archives, some writers use "mnemonic" as a synonym for "keyboard shortcut" (Command-Delete), but others seem to imply it can also be used for the special behavior I seek (Command-Option-Delete). But where's the Command-Option-Delete specified?

In NSResponder.html, I see this:

- (BOOL)performMnemonic:(NSString *)aString

Overridden by subclasses to handle a mnemonic. If the character code or
codes in aString match the receiver's mnemonic, the receiver should perform
the mnemonic and return YES. NSResponder's implementation does nothing
and returns NO.

Where does "the receiver's mnemonic" get set? When the normal action handler gets called (Command-Delete), I don't receive an event I can check for optionKeyDown, as I'd do in a classic app, so I assume there's a different approach.

Thanks for the time and effort spent reading and answering these questions. The answers I've received thus far have been wonderful.
John Blackburn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Option-Key "alternative" application behavior == mnemonics? (From: John Blackburn <email@hidden>)

  • Prev by Date: Re: a.out vs .app bundles
  • Next by Date: NSThread and notifications
  • Previous by thread: Re: Option-Key "alternative" application behavior == mnemonics?
  • Next by thread: Contextual menu on NSTabViewItem
  • Index(es):
    • Date
    • Thread