Re: Making NSView respond to command+key equivalent
Re: Making NSView respond to command+key equivalent
- Subject: Re: Making NSView respond to command+key equivalent
- From: Matt Neuburg <email@hidden>
- Date: Sun, 27 Feb 2005 07:42:07 -0800
On or about 2/27/05 4:05 AM, thus spake "Jeremy Dronfield"
<email@hidden>:
>
> On 26 Feb 2005, at 4:17 pm, Matt Neuburg wrote:
>
>> On Thu, 24 Feb 2005 19:47:32 +0100, Arthur VIGAN
>> <email@hidden>
>> said:
>>> my application has just a window (no title bar) that can become key
>>> window, containing an NSView subclass. The view responds to keyDown:
>>> events perfectly well, but when I press commad+key, my keyDown: method
>>> is not called anymore. How can I fix this?
>>
>> There is nothing to fix. Cocoa is behaving in accordance with the
>> documentation, which says that command+key does not result in keyDown:
>> being
>> called.
>
> Where exactly does it say this? If it does make such a bald statement,
> then it is incorrect
<documentation/Cocoa/Conceptual/BasicEventHandling/Concepts/KeyEvents.html>
"When a key event enters a Cocoa application as an NSEvent object, the
application handles it in a way that differs according to the type of
event.... The application handles key equivalents by going down the view
hierarchy in the key window, sending each object the performKeyEquivalent:
message until an object returns YES... If the application processes a key
event and it turns out not to be a key equivalent... then ...the window
object invokes the keyDown: method in the first responder, from whence the
key event travels up the responder chain until it is handled."
The documentation is quite right about this. If an NSView subclass
implements both keyDown: and performKeyEquivalent:, and is the first
responder (or is the first thing in the responder chain, starting at the
first responder, that implements these), then if you press "y", keyDown: is
called, but if you press command-y, performKeyEquivalent: is called. And
conversely, if keyDown: is not implemented, "y" will just beep, and if
performKeyEquivalent: is not implemented, command-y will just beep.
Try it yourself. m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden