GCSupportsControllerUserInteraction
GCSupportedGameControllers
GCSupportsMultipleMicroGamepads
Use Game Controller to support users interacting with your app using a physical or virtual game controller. Game controllers include third-party products, such as the DualShock 4, DualSense, and Xbox, as well as the mouse, keyboard, Siri Remote, and racing wheels.
To support game controllers, add the Game Controller capability (the GCSupports
property) to your project, and Xcode adds the Game Controller framework automatically. Then, choose the types of controllers your app supports (the GCSupported
property) under the Game Controllers capability on the Signing & Capabilities pane.
For controllers other than the racing wheel, follow these steps to process the game controller input in your app:
To get a physical game controller object, register for specific notifications when users connect and disconnect game controllers. Alternatively, you can display a virtual controller for the user to interact with.
Then get a profile object from the physical or virtual controller to access its input elements, such as buttons, triggers, thumbsticks, and directional pads. Profiles encapsulate the hardware details and layout of the input elements on the controller from your app.
To process the input, either get the values directly from the elements or register callbacks for when the user changes their values. Apps running in visionOS receive input events only when the person is looking at the app’s window.
For controllers that support haptics, you can provide feedback to the user by creating an engine that manipulates the controller’s actuators.
Users may remap game controller elements in Settings and Preferences, so be sure to display the correct input element in your interface. If the has
property is true
, the user remapped elements and you can get the mapping between the actual and alias elements using the mapped
and mapped
methods.
To support racing wheel devices in your macOS app, see Racing wheel device support.
GCSupportsControllerUserInteraction
GCSupportedGameControllers
GCSupportsMultipleMicroGamepads
class GCEventViewController
protocol GCDevice
class GCController
class GCRacingWheel
class GCKeyboard
class GCMouse
class GCMotion
class GCDeviceBattery
class GCDeviceHaptics
class GCDeviceLight
class GCVirtualController
protocol GCTouchedStateInput
protocol GCPressedStateInput
var kIOHIDGCSyntheticDeviceKey : String
typealias GCDeviceElement
typealias GCDeviceAxisInput
typealias GCDeviceButtonInput
typealias GCDeviceTouchpad
typealias GCDeviceDirectionPad