Re: performKeyEquivalent called twice for some key strokes
Re: performKeyEquivalent called twice for some key strokes
- Subject: Re: performKeyEquivalent called twice for some key strokes
- From: Ken Thomases <email@hidden>
- Date: Mon, 26 Aug 2013 10:35:26 -0500
On Aug 23, 2013, at 8:17 AM, Leonid Romanov wrote:
> Pressing "Command +" results in two -performKeyEquivalent calls. Here is a stack trace snippet for the first call:
>
> 1 AppKit 0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
> 2 AppKit 0x00007fff903da442 -[NSView performKeyEquivalent:] + 166
> 3 AppKit 0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
> 4 AppKit 0x00007fff903da259 -[NSWindow performKeyEquivalent:] + 64
> 5 AppKit 0x00007fff903da044 -[NSApplication _handleKeyEquivalent:] + 462
> 6 AppKit 0x00007fff90297173 -[NSApplication sendEvent:] + 4480
>
>
> And for the second call:
>
> 1 AppKit 0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
> 2 AppKit 0x00007fff903da442 -[NSView performKeyEquivalent:] + 166
> 3 AppKit 0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
> 4 AppKit 0x00007fff903da259 -[NSWindow performKeyEquivalent:] + 64
> 5 AppKit 0x00007fff903da044 -[NSApplication _handleKeyEquivalent:] + 462
> 6 AppKit 0x00007fff900e3927 -[NSApplication _handleSpecialAlternateKeyEquivalent:] + 656
> 7 AppKit 0x00007fff9029718e -[NSApplication sendEvent:] + 4507
>
> As you can see, the second -performKeyEquivalent call is initiated by -[NSApplication _handleSpecialAlternateKeyEquivalent:]. So, could anyone tell me what is so special about "Command +" key stroke that it warrants not one, but two -performKeyEquivalent calls, and how do I filter out the second call?
Did your implementation of -performKeyEquivalent: return YES? If not, then you have no reason to assume it won't be called again. In fact, some paths to a second call are known (although I'm not familiar with this particular one). For example, see WWDC 2010 video Session 145 - Key Event Handling in Cocoa Applications, around the 9:40 mark.
If you can't redesign your code so that it tolerates a second call (or prevents it by returning YES), then you might look for ways to track when a new, not-seen-before event begins dispatch. You could observe NSApplicationDidUpdateNotification or NSWindowDidUpdateNotification. You could subclass NSApplication and override -sendEvent: just to reset a flag. Etc.
Regards,
Ken
_______________________________________________
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