Silencing beeps from nonexistent key equivalents
Silencing beeps from nonexistent key equivalents
- Subject: Silencing beeps from nonexistent key equivalents
- From: Kevin Boyce <email@hidden>
- Date: Mon, 9 Jan 2006 22:01:29 -0500
Hi there,
I am developing an app that plays sound cues for theatre work, from a
list shown in a subclass of NSTableView. I'd like to make sure no
extraneous sounds (e.g. SysBeep) are played while it's running.
Cocoa kindly beeps when you type an invalid key, so I need to stop
that from happening. I've tried two approaches, neither of which I
was able to implement satisfactorily:
1. Capture all keypresses.
This should be easy, right? keyDown events travel up the responder
hierarchy, and key-equivalent events travel down the view hierarchy.
I have a keyDown method in my NSTableView subclass, which "handles"
any key event (usually by doing nothing, but in some cases by playing
a sound or whatever). That part works like a charm; my problem is
the key equivalents. I added a performKeyEquivalent method to my
NSTableView subclass, which sure enough gets called, but doesn't act
quite as I'd hoped. I thought I could just send the event to the
main menu, and then always return YES regardless of what the menu
returns.
That works for almost everything, except for the arrow keys.
Apparently those are sent as keyEquivalent events first, and then
sent as keyDown events if nobody handles them as key equivalents. Is
that correct? And if so, are there other keys that are done that way?
Then there's my other attempt at eliminating extraneous sounds:
2. Turn off SysBeep while I'm in control.
Yes, I know it's rude to grab the machine for myself, but when the
sound output is connected to a big amp and speakers for a live
performance, frankly I don't care if other apps want to make noise,
they can just keep their yap shut! So I call SndSetSysBeepState to
disable the system beep when I start up, and again to enable when I
quit.
This works almost perfectly. When my app is running, nonexistent
command-key combos make no sound, in my app or in others. Hey, even
the other alert sounds that Mail.app makes are silenced. Excellent!
BUT! When I quit my app, the Mail.app alert sounds are *still*
silenced. Mail does return to SysBeeping when I hit a command-key
combo that doesn't exist, so my re-enabling seems to have worked.
Why have the other alerts gone away?
This second method is what I'd prefer, but only if I can do it
without messing up other apps. Unless it's a bug in Mail, in which
case I may do it anyway.
Versions I'm using:
Xcode 2.0 (yes I know, I've downloaded 2.2, and am saving up for an
Intel mini)
OS 10.4.3
QT 7.0.3
Mail 2.0.5
Thanks in advance for any help or pointers.
-Kevin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden