How to intercept the space key in an NSTextField
How to intercept the space key in an NSTextField
- Subject: How to intercept the space key in an NSTextField
- From: Frank Bitterlich <email@hidden>
- Date: Fri, 05 Jun 2015 17:18:25 +0200
I’m having trouble finding a solution for a seemingly simple problem.
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.
Subclassing NSTextField and implementing -keyDown dow not work; it is never called. (-keyUp, OTOH, is called - but that does not allow me to „intercept“ and filter out the space character. Or does it?)
This…
NSText *fieldEditor = [self.view.window fieldEditor:YES forObject:nil];
fieldEditor.delegate = self;
… does not appear to help either; the delegate method I was hoping for, -textDidChange, is not called either.
Somebody on StackOverflow suggested to „return my own field editor“, but based on my experiments it seems to be hugely complicated to supply your own NSText subclass there.
I thought it would be simple, because a long time ago I wrote a similar app in REAL Studio, which did allow me to subclass the Text Field class and implement a keydown event to do this.
Any suggestions?
Thanks,
Frank+++
_______________________________________________
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