Here's my code, simplified for brevity:
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
var fooController: FooController!
func applicationDidFinishLaunching(aNotification: NSNotification) {
self.fooController = FooController(frame: self.window.frame)
self.window.contentViewController = self.fooController
self.window.makeFirstResponder(self.fooController)
}
}
class FooController: NSViewController {
override func mouseUp(theEvent: NSEvent) {
print("foo")
}
override func keyUp(theEvent: NSEvent) {
print("bar")
}
}
My MainMenu.xib has a single Window which you can see referenced above in AppDelegate.
When I press a button on my keyboard, I see "bar" in the console. When I click my mouse I see nothing. Once I click my mouse, no further key events are registered.
What am I missing? Why are mouse events stealing the responder chain away, and where is it going?
Like @Willeke mentioned, the first responder is probably changed through the mouse click.
You can set the first responder on mouse down like that:
Now you should be able to receive all events.