• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Silencing beeps from nonexistent key equivalents
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Silencing beeps from nonexistent key equivalents


  • Subject: Re: Silencing beeps from nonexistent key equivalents
  • From: Kevin Boyce <email@hidden>
  • Date: Sat, 14 Jan 2006 14:12:12 -0500


On Jan 9, 2006, at 10:48 PM, Jim Correia wrote:

On Jan 9, 2006, at 10:01 PM, Kevin Boyce wrote:

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.

Read the documentation for noResponderFor:.

<http://developer.apple.com/documentation/Cocoa/Conceptual/ BasicEventHandling/Concepts/ActionEventMsg.html>

Thanks for the tip. It looked promising, but it didn't work for me. AFAICT, noResponderFor: is only called for pure keyDown events, not for keyEquivalent events. The real problem events turn out to be function keys, because they are first handled as key equivalents (sent down the view hierarchy of the key window, then to the main menu), and then if still unhandled they're sent up the responder chain as keyDown events.


Which meant I couldn't just stop handling the event after checking the menu, or I'd never get the arrow key events in my tableView's keyDown: handler. Once I figured out the problem is just with function keys, the answer (as usual, once you know it) is easy. I just subclass the main menu, and override performKeyEquivalent:

- (BOOL)performKeyEquivalent:(NSEvent *)anEvent
{
	BOOL didIt = [super performKeyEquivalent:anEvent];

	if( !didIt )
	{
		if( ! ([anEvent modifierFlags] & NSFunctionKeyMask ) )
		{
			// It's not a function key.  Stop here.
			didIt = YES;
		}
	}
	return didIt;
}

If anyone thinks this is sub-optimal, feel free to correct me. Otherwise, here it is for anyone else who wants to prevent or avoid the system beep from unhandled keys or unhandled menu items. There, that should be enough keywords for the search engine!

-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


References: 
 >Silencing beeps from nonexistent key equivalents (From: Kevin Boyce <email@hidden>)
 >Re: Silencing beeps from nonexistent key equivalents (From: Jim Correia <email@hidden>)

  • Prev by Date: URLWithString:relativeToURL:
  • Next by Date: Image loading design suggestions ?
  • Previous by thread: Re: Silencing beeps from nonexistent key equivalents
  • Next by thread: Getting started with WebKit plugins
  • Index(es):
    • Date
    • Thread