我试图获得自定义NSTextFieldCell
(在NSOutlineView
内)以在按下ESC键时结束编辑,但无法找到任何方法来完成此操作。我试图为NSControlTextDidChangeNotification
-通知添加一个观察者,但它没有为ESC-key触发,也没有在NSOutlineView
中触发keyDown
。
Esc触发NSResponder中的-cancelOperation
。你可以试着在你的响应链中处理这个
接受的答案是正确的。详细说明:为了捕捉ESC键事件,你可以在NSViewController(或你正在使用的NSResponder的任何其他衍生物)中重写cancelOperation方法。下面是我的代码在Swift 4.x中的样子。
class PopUIcontroller: NSViewController, NSTextFieldDelegate {
override func cancelOperation(_ sender: Any?) {
print("trying to cancel! Here I will do stuff to handle ESC key press!")
}
}
NSWindowController can't capture ESC without WebView is add to the window