• 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: Intercepting Some Keyboard Events for NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Intercepting Some Keyboard Events for NSTextView


  • Subject: Re: Intercepting Some Keyboard Events for NSTextView
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 15 Jul 2002 10:13:27 -0700

On Monday, July 15, 2002, at 08:12 AM, John Nairn wrote:

both have the same problem. They both consider "Return" and "Enter" to be the same thing which is to insert a new line. I was trying to intercept keyboard events before the NSTextView processes them so I can pick out Return and Enter as separate events. For now, just distinguishing "Return" and "Enter" will solve my problem, but it would nice to know a general way to intercept keyboard events before the first responder for future needs that might want to trap more. For example, the doCommandBySelector approach does not even see ordinary key presses. The custom classes I tried (following examples in books) relied on the window being the first responder which seemed to disrupt Cocoa's automatic handling of responders with features like focus rings, selections coloring, etc.

You can look at [NSApp currentEvent] to distinguish return vs. enter. Ordinary key presses can be obtained using other delegate methods, e.g. textView:shouldChangeTextInRange:replacementString:.

I highly recommend using the delegate methods rather than trying to override keyDown:, if at all possible. You should not override NSTextView's keyDown: unless you know exactly what you are doing, because it intervenes in the event stream before any input management or key binding occurs. Many keys have special meanings to special input methods, so you need to be careful not to e.g. swallow a return that an input manager needs. At a minimum you would need to test such an override using Japanese, Chinese, Korean, etc.

Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Intercepting Some Keyboard Events for NSTextView
      • From: John Nairn <email@hidden>
References: 
 >Re: Intercepting Some Keyboard Events for NSTextView (From: John Nairn <email@hidden>)

  • Prev by Date: Re: Applying Style Masks to IB Windows
  • Next by Date: Re: Intercepting Some Keyboard Events for NSTextView
  • Previous by thread: Re: Intercepting Some Keyboard Events for NSTextView
  • Next by thread: Re: Intercepting Some Keyboard Events for NSTextView
  • Index(es):
    • Date
    • Thread