How to prevent SpriteKit overlay in SceneKit to get all key down events

36 Views Asked by At

I have a SceneKit view that works very fine. its view controller gets and manages the key down events in an override of keyDown(with event: NSEvent).

But, as soon as I add a SceneKit overlay like this:

let skScene             = MySKScene(fileNamed: "Level1.scnassets/3_overlay.sks")!
scnView.overlaySKScene  = skScene
skScene.isUserInteractionEnabled    = false

The SKScene gets all the key down events (Level1.scnassets/3_overlay.sks is just an empty scene).

Worse, I did trace the events like this:

class MySKScene: SKScene {
    public override func keyDown(with event: NSEvent) {
        print("I reach here !")
        print("  isUserInteractionEnabled: \(self.isUserInteractionEnabled)")
        
        func printResponderChain(indent: String, resp: NSResponder) {
            print(indent + "type: \(type(of: resp))")
            if let father = self.nextResponder {
                printResponderChain(indent: indent + "  ", resp: father)
            }
        }
        printResponderChain(indent: "", resp: self)
    }
}

I get this:

I reach here !
  isUserInteractionEnabled: false
type: MySKScene

So the SKScene tells me at the same time:

  1. the keyDown method is called
  2. isUserInteractionEnabled is false
  3. the responder chain is only made of the SKScene itself

How to fully disable the SKScene ?

0

There are 0 best solutions below