Reputation: 35783
I have a Cocoa application that captures keypresses through a custom view in the view hierarchy. This view implements the keyUp
and keyDown
methods, and the keypresses are received. Even so, Cocoa still insists on playing the system error sound/ding every time I press a key. Any solutions?
Note: Although I tried to make this view first responder, it didn't work. That may have something to do with it.
Upvotes: 4
Views: 1399
Reputation: 22948
If you have unsuccessfully tried to make the view the first responder, it's most likely because NSView
returns NO
for acceptsFirstResponder
. You can have your NSView
subclass override acceptsFirstResponder
to return YES:
- (BOOL)acceptsFirstResponder {
return YES;
}
That should eliminate the beeps. Alternatively, you could have the NSView
subclass override NSResponder
's performKeyEquivalent:
method to return YES, which should also eliminate the NSBeeps:
- (BOOL)performKeyEquivalent:(NSEvent *)event {
return YES;
}
UPDATE:
Not sure what to suggest. I actually wrote a "Keyboard Cleaner Helper" app that's designed to basically do something similar to what you want. (I used it on my laptop when I wanted to clean the keyboard and didn't the hundreds of key presses to randomly rename files or result in repeated error beeps).
Sample project: http://www.markdouma.com/developer/KeyboardCleanerHelper.zip
Running that app, I can't get it to beep at all (notice calls are logged to Console).
Upvotes: 8