Search code examples
objective-cmacoscocoansoutlineview

How can I detect Escape key pressed in NSOutlineView?


I have Created Simple cocoa app. In which I use NSOutlineView. Now my task is to get the event of Escape Key pressed. In my appdelegate.m I implemented all require method for NSOutlineView.


Solution

  • SubClass your NSOutlineView and capture its key down event as:

    - (void)keyDown:(NSEvent *)theEvent
    {       
        switch([theEvent keyCode]) 
        {
            case 53: // esc
                NSLog(@"ESC");
                // Implement the functionality you want when esc is pressed
    
                break;
    
            default:
               [super keyDown:theEvent];
        }
    }