Re: How to intercept the space key in an NSTextField
Re: How to intercept the space key in an NSTextField
- Subject: Re: How to intercept the space key in an NSTextField
- From: Ken Thomases <email@hidden>
- Date: Fri, 04 Sep 2015 06:12:33 -0500
On Jun 8, 2015, at 8:01 AM, Frank Bitterlich <email@hidden> 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 (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