Cocoa: Key down event on NSView not firing
-
29-05-2021 - |
Pergunta
I have made a custom NSView and have implemented the keyDown:
method. However, when I press keys the method is never called. Do I have to register to receive those events? fyi, I am making a document based application and can handle this code anywhere (doesn't have to be in this view). What is the best place to do this in a document based application such that the event will occur throughout the entire application?
Solução
You need to override -acceptsFirstResponder
to return YES
.
Outras dicas
In Swift:
class MDView: NSView {
override var acceptsFirstResponder: Bool { return true }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow