Re: Background Helper app - brings up UI element, needs CMD-C/X/V
Re: Background Helper app - brings up UI element, needs CMD-C/X/V
- Subject: Re: Background Helper app - brings up UI element, needs CMD-C/X/V
- From: Ken Thomases <email@hidden>
- Date: Mon, 28 Sep 2015 16:38:52 -0500
On Sep 28, 2015, at 4:22 PM, Alex Kac <email@hidden> wrote:
>
> I guess I need more help than that. Here is what I’ve got:
>
> NSViewController - with a NIB that has a plain NSView, with an NSTextField in it. Using an NSPopover, the NSViewController is the content for the popover.
>
> My only two classes are the NSApplication delegate, and the NSViewController. Neither -keyDown nor -performKeyEquivalent: get called there. I’m reading this:
> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html
Use a custom view class. You can replace the "plain NSView" in your description above with a custom subclass of NSView. Or you can use a custom subclass of NSTextField. Either will work. The search for a view which handles a key equivalent goes through the entire view hierarchy of a window, not just the responder chain or anything like that.
There's a sample implementation here <http://web.archive.org/web/20100126000339/http://www.cocoarocket.com/articles/copypaste.html>. That code uses [[self window] firstResponder] as the "to" parameter for calls to -[NSApplication sendAction:to:from:], but you can just pass nil to target the first responder.
The code is also a bit too strict in checking the event's modifierFlags. It will fail to invoke the edit actions if Caps Lock is down, for example. I would write that as:
if ((event.modifierFlags & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)) == NSCommandKeyMask) …
> From reading there, since I have no NSWindow, and no NSMenu, there is no key-view loop or NSApplication has nothing to send me the command key equivalents for.
There is a window for the popover, it's just private to the popover implementation. There is a key-view loop. If a popover has multiple text fields, for example, you can tab from one to the next.
> I’m wondering if perhaps I need to use a global monitor for events while the popover is up, and remove it when its dismissed.
>
> I don’t mind handling the events myself and processing them - but beyond using a global monitor for events, I’m not sure how to set them up and get them in my NSViewController…
A global event monitor is for events *not* targeted at your application. A local event monitor is for events targeted at your application. But neither should be necessary for this purpose.
Regards,
Ken
_______________________________________________
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