NSWindow does not receive spacebar event in KeyDown

My Mac app has two windows. When one of them is active and I press the spacebar, then it is captured by my keyDown override for the window. But for the other window, spacebar does not trigger any event for keyDown. Other characters like letters trigger the event for both windows. Why would spacebar work on one window but not the other?


Thanks

Bob

Accepted Reply

The window that works is a big MTKView. The one that doesn't is a complicated stack of Cocoa windows, including an NSOutlineView and an NSTableView -- a timeline basically. There are no overrides for either sendEvent or performKeyEquivalent.


In order to not have to activate each window before using the mouse/pen in it, I have this override in the MTKView and the NSOutlineView. Not sure if that makes any difference.


override func acceptsFirstMouse(for event: NSEvent?) -> Bool {

return true

}


Also this one in the outline view:


override var needsPanelToBecomeKey:Bool { get { return false } }



Maybe NSOutlineView or NSTableView or the pile of associated scroller subviews intercept the space bar for some reason?

.

.

.


Ahh! Okay, so from this stack overflow thread I found that NSTableView *does* capture the spacebar.

https://stackoverflow.com/questions/27954538/nstableview-how-to-remove-the-spacebar-event-listener


I was able to get it to work by overriding keyDown for the NSTableView. I added in overrides for the outline view in case it did the same thing.

Replies

There's not enough to really go on here. What's in the view hierarchy of each window? Is there a view that is focused in one window but not in the other? Does anything in the view hierarchy override -performKeyEquivalent: ? Does either window class override -sendEvent: ?

The window that works is a big MTKView. The one that doesn't is a complicated stack of Cocoa windows, including an NSOutlineView and an NSTableView -- a timeline basically. There are no overrides for either sendEvent or performKeyEquivalent.


In order to not have to activate each window before using the mouse/pen in it, I have this override in the MTKView and the NSOutlineView. Not sure if that makes any difference.


override func acceptsFirstMouse(for event: NSEvent?) -> Bool {

return true

}


Also this one in the outline view:


override var needsPanelToBecomeKey:Bool { get { return false } }



Maybe NSOutlineView or NSTableView or the pile of associated scroller subviews intercept the space bar for some reason?

.

.

.


Ahh! Okay, so from this stack overflow thread I found that NSTableView *does* capture the spacebar.

https://stackoverflow.com/questions/27954538/nstableview-how-to-remove-the-spacebar-event-listener


I was able to get it to work by overriding keyDown for the NSTableView. I added in overrides for the outline view in case it did the same thing.

Uvibiobboobnoon