Search code examples
cocoansviewnsopenglview

Annoying Bump Sound with Keyboard Events in NSOpenGLView subclass


I've overridden an NSOpenGLView to handle keyboard events. The event detection is working fine, but every time I press a key I hear and annoying bump sound. How can I tell my view to chill out?

Here's what my keyUp: method looks like:

-(void) keyUp:(NSEvent *)theEvent
{
    NSString *characters = [theEvent charactersIgnoringModifiers];

    if ( [characters length] != 1 )
        return;

    unichar keyChar = [characters characterAtIndex:0];

    if ( keyChar == NSLeftArrowFunctionKey ) 
    {
        //do something
        return;
    }

    if ( keyChar == NSRightArrowFunctionKey ) 
    {
        //do something
        return;
    }

    if ( keyChar == NSUpArrowFunctionKey ) 
    {
        //do something
        return;
    }

    if ( keyChar == NSDownArrowFunctionKey ) 
    {
        //do something
        return;
    }
}

Solution

  • Hard to tell without your code but I'd guess you passed the event up to super even though you "consumed" it. The beep tone is saying "nobody is handling this event so keyboard input isn't allowed." If you consume (handle) the event, don't pass it to super or the system will assume your view didn't handle the event.