On Jun 8, 2015, at 8:01 AM, Frank Bitterlich <bitterli...@gsco.de> wrote:
> I’m having trouble finding a solution for a seemingly simple problem. This email is kind of old and just emerged from moderation limbo, but in case you're still stuck… > I need an NSTextField that will „catch“ the space key, and instead of adding > a blank to its content, will trigger something different. > > The reason: I have a window where I need to trigger starting/stopping of a > clock by pressing the spacebar, regardless of whether a text field currently > has the focus or not. So, you don't need the text field to catch the space key, you need _something_ to catch it even if the text field has focus. Try implementing -performKeyEquivalent: on the window or a high-level view within it. Examine the event. Do whatever is appropriate with respect to starting or stopping the clock if it meets your criteria (like it's a key-down for the Space key). If it should be consumed, return YES. Return NO for anything you don't handle. If that doesn't work, try a local event monitor. Create it using +[NSEvent addLocalMonitorForEventsMatchingMask:handler:]. Regards, Ken _______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com