On May 29, 2008, at 10:13 AM, Aki Inoue wrote:

When you want to handle key events in NSTextView, see - textView:doCommandBySelector: delegate method. http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html#/ /apple_ref/occ/instm/NSObject/textView:doCommandBySelector:

Let me summarize what was said when this question last came up:

Here is the normal sequence when a text view receives key 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. An arbitrary text view can be made to act in either of these ways by calling setFieldEditor:.

To do something special for an enter vs. a return, you should be able to implement the text view delegate method

- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector: (SEL)aSelector;

and, if aSelector == @selector(insertNewline:), examine [NSApp currentEvent] to make sure that it is a key event (it should be, unless someone is calling doCommandBySelector: directly), and if so what key was pressed.

Alternatively, if you wished to do this in a text view subclass rather than in the delegate, you could override insertNewline: to similar effect.

Douglas Davidson
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to