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.

有帮助吗?

解决方案

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];
    }
}

其他提示

Well you can find out the whther escape key was pressed or not try below one line and used in your method where it is required:-

NSUInteger flags = [theEvent keycode];
//After that 

If (flags==53)
{

NSlog(@"Escape key pressed");
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top