Re: Key event handling theory
Re: Key event handling theory
- Subject: Re: Key event handling theory
- From: Brian Webster <email@hidden>
- Date: Fri, 4 Jan 2002 15:40:28 -0600
On Friday, January 4, 2002, at 03:12 PM, Greg Titus wrote:
NSResponder already implements -keyDown: to pass along the key
events to -interpretKeyEvents: so all of that is basically done
for you. To implement your simple example, all you really have
to do is implement a method called -deleteBackwards:.
The NSResponder machinery will:
1) In -keyDown: pass the event to -interpretKeyEvents:
2) In -interpretKeyEvents: it will do the binding to the
deleteBackwards command and call -doCommandBySelector:
3) In -doCommandBySelector: the default implementation just
sees if self responds to the selector and calls it so
4) Your -deleteBackwards: method is invoked.
The way I'd recommend hooking into this is:
* If there is already a command for the keyboard event you are
interested in (like in this example) just implement the command
method (-deleteBackwards:) and leave everything else alone.
* Only override -doCommandBySelector: if you want to add your
own 'chain' of possible handlers, like NSTextView calls its
delegate with -textView:doCommandBySelector:.
* Only override -interpretKeyEvents: if you have some other key
that you want to do something special that isn't currently
defined (for example, making control-alt-tilde be the -frob:
command)
* Only override -keyDown: directly if you want to handle typing
instead of key commands (if you see what I mean...). Be sure to
call the superclass implementation for any key that you don't
explicitly handle so the rest of the machinery still happens.
OK, so does that mean that there's no "automatic" way to bind
keys to selectors, like by loading a key binding dictionary ala
Project Builder? That is, to create a new binding (e.g. for
Shift-Return), I would need to do that in interpretKeyEvents:?
Also, I don't suppose the default key bindings are documented
anywhere (aside from digging through the unicode values in the
StandardKeyBinding.dict file), are they?
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster