• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Enter" key down
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Enter" key down


  • Subject: Re: "Enter" key down
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 29 May 2008 10:22:17 -0700


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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >"Enter" key down (From: Micha Fuhrmann <email@hidden>)
 >Re: "Enter" key down (From: "I. Savant" <email@hidden>)
 >Re: "Enter" key down (From: Aki Inoue <email@hidden>)

  • Prev by Date: Re: "Enter" key down
  • Next by Date: Re: "Enter" key down
  • Previous by thread: Re: "Enter" key down
  • Next by thread: Re: "Enter" key down
  • Index(es):
    • Date
    • Thread