VisionOS - Gamepad steals focus

I am developing a vision os app for controlling an underwater ROV. I have ornaments with telemetry and buttons around a central video view feed. I have custom buttons mappings, such as "A" for locking the depth of the drone. However, when I look at buttons or certain ornaments, my custom gamepad logic is kept from running. This means that when a SwiftUI Button gains focus on visionOS, pressing the controller’s A button triggers the system’s default “click” on that Button rather than my custom buttonA handler. Essentially, focus interception by the system is stealing my A-press events and preventing my custom gamepad logic from running.

Is there a way to disable the built in gamepad interaction and only allow my custom gamepad mappings?

Accepted Answer

I found that using .handlesGameControllerEvents(matching: .gamepad) on the components that I don't want to steal focus fixed the issue.

VisionOS - Gamepad steals focus
 
 
Q