• 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: Best practice for hidden keyboard shortcuts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practice for hidden keyboard shortcuts


  • Subject: Re: Best practice for hidden keyboard shortcuts
  • From: Sandy Martel <email@hidden>
  • Date: Sat, 3 Nov 2007 18:43:07 +1100


What I've been doing since Mac OS X 10.0 is this:

Instanciate an NSMenu in your main nib but don't add it to the menu bar, have an outlet to it in your NSApplication subclass (_hiddenMenu). Implement sendEvent: like this

- (void)sendEvent:(NSEvent *)i_event
{
	if ( [i_event type] == NSKeyDown and
			([i_event modifierFlags] & NSCommandKeyMask) != 0 and
			[_hiddenMenu performKeyEquivalent: i_event] )
	{
		return;
	}
	else
	{
		[super sendEvent: i_event];
	}
}

This let you edit your hidden shortcut and connect their action like normal menu items.

Sandy.


Le 07-11-03 à 13:58, Philip Dow a écrit :

If you all don't mind I'm going to post what I've done. I've seen this show up so many times, and this solution, if it isn't unknowingly screwing things up, feels clean.

In your custom subclass of NSApplication (everybody's doing it!) override sendEvent: Can you feel the power!?

- (void)sendEvent:(NSEvent *)anEvent
{
// is this a keyboard equivalent event ?
// if so does the key window respond to custom keyboard equivalents?
if ( [anEvent type] == NSKeyDown && ( [anEvent modifierFlags] & NSCommandKeyMask ) && [[[self keyWindow] windowController] respondsToSelector:@selector(performCustomKeyEquivalent:)] )
{
// if the key window doesn't have anything to do, pass the message onto super
if ( ![[[self keyWindow] windowController] performSelector:@selector(performCustomKeyEquivalent:) withObject:anEvent] )
[super sendEvent:anEvent];
}
else
{
// let super handle anything else
[super sendEvent:anEvent];
}
}


sendEvent is asking the frontmost window if its window controller responds to custom key events. There I am implementing performCustomKeyEquivalent:(NSEvent*)anEvent, where I check the charactersIgnoringModifiers and modifierFlags to decide how to act.

In truth a view controller responsible for managing the window's actual content does that. The window controller is just passing the message on, but I suppose you could do whatever you want.

Application wide hidden keyboard shortcuts. I guess keyboard equivalents aren't that hard.

-Phil

On Nov 2, 2007, at 11:21 AM, David Spooner wrote:


You may be able to implement the methods in a higher-level responder; this leaves you with the problem of how to distribute the messages to the appropriate views, but you will also have to do that if you take the -sendEvent: route...


dave

On 2-Nov-07, at 11:38 AM, Philip Dow wrote:

Ah, I failed to mention that the views upon which the key equivalents act are not necessarily in focus, so they won't receive the keyDown events.

-Phil

On Nov 2, 2007, at 9:49 AM, David Spooner wrote:

Phil,

I had written a class of view which implements arbitrary key equivalents (with some exceptions, like cmd-tab) by overriding both -performKeyEquivalent: and -keyDown: -- I don't recall the specifics, but I know that both methods are called in different circumstances...

dave




Journler Developer
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


References: 
 >Best practice for hidden keyboard shortcuts (From: Philip Dow <email@hidden>)
 >Re: Best practice for hidden keyboard shortcuts (From: David Spooner <email@hidden>)
 >Re: Best practice for hidden keyboard shortcuts (From: Philip Dow <email@hidden>)
 >Re: Best practice for hidden keyboard shortcuts (From: David Spooner <email@hidden>)
 >Re: Best practice for hidden keyboard shortcuts (From: Philip Dow <email@hidden>)

  • Prev by Date: Re: Choppy Core Animation
  • Next by Date: [WebFrame url] -- How to get the initial URL from WebView or WebFrame?
  • Previous by thread: Re: Best practice for hidden keyboard shortcuts
  • Next by thread: Transparent divider
  • Index(es):
    • Date
    • Thread