How to receive keyboard/mouse on VisionOS?

I tried using the GameController APIs for this, but they didn't seem to work. Is that the recommended API for handling keyboard/mouse? The notifications for mouse and keyboard connect/disconnect don't seem to be defined for visionOS.

The visionOS 2.0 touts keyboard and mouse support. The simulator can even forward keyboard/mouse to the app. But there don't seem to be any sample code of how to programatically receive either of these. The game controller works fine (on device, not on Simulator).

Answered by Alecazam in 812512022

Looks like the GC calls do work for mouse/keyboard. I just need the shorter notification names.

notifications.addObserver(forName: .GCKeyboardDidConnect, object: nil, queue: .main) { [weak self] note in
            if let controller = note.object as? GCKeyboard {
                self?.addKeyboard(controller)
            }
        }
Accepted Answer

Looks like the GC calls do work for mouse/keyboard. I just need the shorter notification names.

notifications.addObserver(forName: .GCKeyboardDidConnect, object: nil, queue: .main) { [weak self] note in
            if let controller = note.object as? GCKeyboard {
                self?.addKeyboard(controller)
            }
        }
How to receive keyboard/mouse on VisionOS?
 
 
Q