views:

17

answers:

1

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;
    }
}
+1  A: 

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.

Joshua Nozzi
Sorry about that. I thought it was a more general question. I've added code to my original post. You may very well be right about the event consumption, but I can't seem to figure out how to consume an event.
helixed
See listing 5-2 here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html%23//apple_ref/doc/uid/10000060i-CH7-SW1 ... this is the "official" way to do what you're trying to do. The methods come from NSResponder (of which NSView is a subclass).
Joshua Nozzi