I am subclassing NSWindowController from File-> New and with the option "With XIB for user interface". Therefore, I create 3 new files. Then I use Interface Builder to add only one view to the window.
And this code in MyWindowController.m:
- (void)keyDown:(NSEvent *)theEvent{ NSLog(@"%@", theEvent); }
- First test, add one NSButton and run the project.
- Second test, add one WebView (NSButton deleted) and run the project.
In both tests, the window displays correctly. But the difference is:
- (NSButton) I can see the log output when I press keys like "a", "b", ..., but not the ESC key
- (WebView) I can see the log output when I press keys like "a", "b", ..., and the ESC key also
I am changing NSButton to a different type of view, as well as my custom view, all act as the first case.
My question is:
- Why can't NSWindowController grab the ESC key in the first case?
- Why NSWindowController grabs the ESC key using WebView as the first responder.
- How can NSWindowController grab an ESC key without a WebView?
source share