Re: Key event handling theory
Re: Key event handling theory
- Subject: Re: Key event handling theory
- From: Brian Webster <email@hidden>
- Date: Sat, 5 Jan 2002 10:50:56 -0600
On Friday, January 4, 2002, at 04:25 PM, Greg Titus wrote:
On Friday, January 4, 2002, at 01:40 PM, Brian Webster wrote:
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?
No, I just thought you wanted to avoid a global change.
Overriding -interpretKeyEvents: to add the binding in a single
class would make shift-return do something different only in
that class. Creating a binding for shift-return to a new
selector in a key binding dictionary will set it for the whole
application or globally -- which may be a good thing or may be
a bad thing depending on your intention. If you bind
shift-return to -frob:, for instance, then I think what will
happen is that it will work fine in your view as long as you
just implement -frob:, but I'd expect that NSTextView's would
then do nothing when you hit shift-return in them (since they
don't have a -frob: method) instead of acting like a normal
return. That's just a guess though - I haven't actually tried
it.
So is there any method I can call in Cocoa to load a key binding
dictionary, or do I have to do the key->selector mapping
manually in -interpretKeyEvents:, looking up each keystroke in
the dictionary and calling -doCommandBySelector: with the
corresponding selector?
Also, it appears that NSResponder's implementation of keyDown:
doesn't call interpretKeyEvents:. The docs say it just passes
the event on to the next responder in the chain, so implementing
keyDown: to call interpretKeyEvents: is necessary if anyone want
to go this route.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster