• 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 *all* keystrokes in NSView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Intercepting *all* keystrokes in NSView?


  • Subject: Re: Intercepting *all* keystrokes in NSView?
  • From: email@hidden
  • Date: Tue, 05 Aug 2014 11:55:55 +0900


> On 2014/05/29, at 13:57, Alex Hall <email@hidden> wrote:
>
> Hello list,
> I have a subclass of NSView that is set to be my window's first responder. It intercepts keystrokes by implementing keyUp: and performKeyEquivalent: but it doesn't do quite what I need

You need to read the event programming guide and then read it again.
Views don't receive all key events and they don't get first shot at them either.

In short, you're going to want to look at either NSEvent's global or local monitor
Or
CGEventTap

Most of what you do id the same either way.

Biggest gotchas are that some key events are intercepted and handled at the IOKit level. (Media Keys)
And that Function and modifier keys are approached differently.
And that arrow keys are numpad keys.
And some keys exist on on some keyboard layouts and not others. Localized keyboards.

Also carefully consider input methods, by intercepting events you can actually be intercepting them before they are converted to what the user intends with multistage input ( Japanese for example )
This may or may not be ok.

Definitely be cautious in thinking in terms of key codes.
Key codes by the way are mostly documented in Carbon headers but can be useful practically.

It's not really well documented but there are a lot of responder methods that are part of the Cocoa text system that can enable a lot of customization. They also alleviate the sandbox issues that can arise with monitors and event taps.
_______________________________________________

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: 
 >Intercepting *all* keystrokes in NSView? (From: Alex Hall <email@hidden>)

  • Prev by Date: Re: Swift video/PDF files within the WWDC 2014 video list
  • Next by Date: Re: Intercepting *all* keystrokes in NSView?
  • Previous by thread: Intercepting *all* keystrokes in NSView?
  • Next by thread: Re: Intercepting *all* keystrokes in NSView?
  • Index(es):
    • Date
    • Thread