Re: Return and Enter keys in NSTextView
Re: Return and Enter keys in NSTextView
- Subject: Re: Return and Enter keys in NSTextView
- From: Douglas Davidson <email@hidden>
- Date: Wed, 29 Aug 2001 16:31:03 -0700
On Wednesday, August 29, 2001, at 03:45 PM, Richard Schreyer wrote:
I've overridden keyDown: in NSTextView, and need to find out when the
user has pressed either the Enter or Return keys.
I've looked through the docs of NSEvent, but I don't see any constants
for these keys like there are for the Modifiers.
Overriding NSTextView's keyDown: usually is not the best thing to do.
This will get you raw key events as they come in, before they have been
processed by any of the text machinery--in particular, input management
or key binding. Do you really want every press of the return key, even
those that might end up being passed to some input method rather than
ending up as returns in the text?
Usually it is better to intervene somewhere else in the processing of
events. NSTextView's keyDown: passes events to interpretKeyEvents:,
which is where they enter key binding and input management. They come
out either as insertText: or as doCommandBySelector: (see NSResponder.h
for these three methods).
In particular, an enter or return will (with the standard key bindings)
end up using doCommandBySelector: to call insertNewline: on the
NSTextView. If the textview is not a field editor, this will call
insertText: to insert a newline character. If it is a field editor (for
example, when editing a textfield) this will end editing instead.
You may wish to override insertNewline: instead. This will tell you
when the user does the equivalent of pressing enter or return, by
whatever means, or however they have remapped their keybindings.
To answer your original question, though, look in NSText.h.
Douglas Davidson