cocoa - NSWindowController can't capture ESC without WebView is added to the window -


i create subclass of nswindowcontroller file->new, , "with xib user interface" option checked. create 3 new files. use interface builder add 1 view window.

and have code in mywindowcontroller.m:

- (void)keydown:(nsevent *)theevent{     nslog(@"%@", theevent); } 
  1. first test, add 1 nsbutton, , run project.
  2. second test, add 1 webview(nsbutton deleted), , run project.

in both tests, window shows correctly. diffrence is:

  1. (nsbutton)i can see log output when press keys 'a', 'b', ..., not esc key
  2. (webview)i can see log output when press keys 'a', 'b', ..., and esc key well

i change nsbutton other view type, , custom view, act first case.

my qustion is:

  1. why can't nswindowcontroller capture esc key down in first case?
  2. why nswindowcontroller capture esc key down webview first responder.
  3. how can nswindowcontroller capture esc key without webview?

see nsresponder canceloperation: docs: https://developer.apple.com/library/mac/ipad/#documentation/cocoa/reference/applicationkit/classes/nsresponder_class/reference/reference.html

this method bound escape , command-. (period) keys. key window first searches view hierarchy view key equivalent escape or command-., whichever entered. if none of these views handles key equivalent, window sends default action message of canceloperation: first responder , there message travels responder chain. if no responder in responder chain implements canceloperation:, key window searches view hierarchy view key equivalent escape (note may redundant if original key equivalent escape). if no such responder found, cancel: action message sent first responder in responder chain implements it.

and if want handle esc key in nswindowcontroller subclass define cancel: method in it.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -