public class GCController extends NSObject implements GCDevice
1: Querying for the the current array or controllers using [GCController controllers]. 2: Registering for Connection/Disconnection notifications from NSNotificationCenter.
Only controllers that support one of the allowed profiles, such as GCExtendedGamepad, will be enumerated. Check for the profile supported before using a controller in your application. Ignore a controller that doesn't support a profile that suits your application, as the user will expect their controller to either be fully supported or not supported at all.
| Modifier and Type | Class and Description |
|---|---|
static interface |
GCController.Block_controllerPausedHandler_ret |
static interface |
GCController.Block_setControllerPausedHandler |
static interface |
GCController.Block_startWirelessControllerDiscoveryWithCompletionHandler |
NSObject.Function_instanceMethodForSelector_ret, NSObject.Function_methodForSelector_ret| Modifier | Constructor and Description |
|---|---|
protected |
GCController(org.moe.natj.general.Pointer peer) |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
accessInstanceVariablesDirectly() |
static GCController |
alloc() |
static GCController |
allocWithZone(org.moe.natj.general.ptr.VoidPtr zone) |
static boolean |
automaticallyNotifiesObserversForKey(java.lang.String key) |
GCDeviceBattery |
battery()
Gets the battery information if controller supports one
|
static void |
cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget) |
static void |
cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument) |
GCController |
capture()
Polls the state vector of the controller and saves it to a new and writable instance of GCController.
|
static NSArray<java.lang.String> |
classFallbacksForKeyedArchiver() |
static org.moe.natj.objc.Class |
classForKeyedUnarchiver() |
GCController.Block_controllerPausedHandler_ret |
controllerPausedHandler()
Set this block to be notified when a user intends to suspend or resume the current game state.
|
static NSArray<? extends GCController> |
controllers()
Get a list of controllers currently attached to the system.
|
static GCController |
controllerWithExtendedGamepad()
Creates a controller with an extended gamepad profile.
|
static GCController |
controllerWithMicroGamepad()
Creates a controller with a micro gamepad profile.
|
static GCController |
current()
The most recently used game controller.
|
static java.lang.String |
debugDescription_static() |
static java.lang.String |
description_static() |
GCExtendedGamepad |
extendedGamepad() |
GCGamepad |
gamepad()
Gets the profile for the controller that suits current application.
|
NSObject |
handlerQueue()
The dispatch queue that element value change handlers are submitted on.
|
GCDeviceHaptics |
haptics()
Gets the haptics for the controller, if one exists.
|
static long |
hash_static() |
GCController |
init() |
static NSObject.Function_instanceMethodForSelector_ret |
instanceMethodForSelector(org.moe.natj.objc.SEL aSelector) |
static NSMethodSignature |
instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
instancesRespondToSelector(org.moe.natj.objc.SEL aSelector) |
boolean |
isAttachedToDevice()
A controller may be form fitting or otherwise closely attached to the device.
|
boolean |
isSnapshot()
A controller may represent a real device managed by the operating system, or a virtual snapshot created by the developer.
|
static boolean |
isSubclassOfClass(org.moe.natj.objc.Class aClass) |
static NSSet<java.lang.String> |
keyPathsForValuesAffectingValueForKey(java.lang.String key) |
GCDeviceLight |
light()
Gets the light for the controller, if one exists.
|
GCMicroGamepad |
microGamepad() |
GCMotion |
motion()
Gets the motion input profile.
|
static GCController |
new_objc() |
GCPhysicalInputProfile |
physicalInputProfile()
Gets the physical input profile for the device.
|
long |
playerIndex()
A player index for the controller, defaults to GCControllerPlayerIndexUnset.
|
java.lang.String |
productCategory()
The product category the controller belongs to.
|
static boolean |
resolveClassMethod(org.moe.natj.objc.SEL sel) |
static boolean |
resolveInstanceMethod(org.moe.natj.objc.SEL sel) |
void |
setControllerPausedHandler(GCController.Block_setControllerPausedHandler value)
Set this block to be notified when a user intends to suspend or resume the current game state.
|
void |
setHandlerQueue(NSObject value)
The dispatch queue that element value change handlers are submitted on.
|
void |
setPlayerIndex(long value)
A player index for the controller, defaults to GCControllerPlayerIndexUnset.
|
static void |
setShouldMonitorBackgroundEvents(boolean value)
Whether the current application should monitor and respond to game controller events when it is not the frontmost application.
|
static void |
setVersion_static(long aVersion) |
static boolean |
shouldMonitorBackgroundEvents()
Whether the current application should monitor and respond to game controller events when it is not the frontmost application.
|
static void |
startWirelessControllerDiscoveryWithCompletionHandler(GCController.Block_startWirelessControllerDiscoveryWithCompletionHandler completionHandler)
Start discovery of new wireless controllers that are discoverable.
|
static void |
stopWirelessControllerDiscovery()
If no more controllers are needed, depending on game state or number of controllers supported by a game, the discovery
process can be stopped.
|
static org.moe.natj.objc.Class |
superclass_static() |
java.lang.String |
vendorName()
A vendor supplied name.
|
static long |
version_static() |
accessibilityActivate, accessibilityActivationPoint, accessibilityAssistiveTechnologyFocusedIdentifiers, accessibilityAttributedHint, accessibilityAttributedLabel, accessibilityAttributedUserInputLabels, accessibilityAttributedValue, accessibilityContainerType, accessibilityCustomActions, accessibilityCustomRotors, accessibilityDecrement, accessibilityDragSourceDescriptors, accessibilityDropPointDescriptors, accessibilityElementAtIndex, accessibilityElementCount, accessibilityElementDidBecomeFocused, accessibilityElementDidLoseFocus, accessibilityElementIsFocused, accessibilityElements, accessibilityElementsHidden, accessibilityFrame, accessibilityHint, accessibilityIncrement, accessibilityLabel, accessibilityLanguage, accessibilityNavigationStyle, accessibilityPath, accessibilityPerformEscape, accessibilityPerformMagicTap, accessibilityRespondsToUserInteraction, accessibilityScroll, accessibilityTextualContext, accessibilityTraits, accessibilityUserInputLabels, accessibilityValue, accessibilityViewIsModal, addObserverForKeyPathOptionsContext, attemptRecoveryFromErrorOptionIndex, attemptRecoveryFromErrorOptionIndexDelegateDidRecoverSelectorContextInfo, autoContentAccessingProxy, awakeAfterUsingCoder, awakeFromNib, class_objc, classForCoder, classForKeyedArchiver, copy, dealloc, debugDescription, description, dictionaryWithValuesForKeys, didChangeValueForKey, didChangeValueForKeyWithSetMutationUsingObjects, didChangeValuesAtIndexesForKey, doesNotRecognizeSelector, fileManagerShouldProceedAfterError, fileManagerWillProcessPath, finalize_objc, forwardingTargetForSelector, forwardInvocation, hash, indexOfAccessibilityElement, isAccessibilityElement, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableArrayValueForKey, mutableArrayValueForKeyPath, mutableCopy, mutableOrderedSetValueForKey, mutableOrderedSetValueForKeyPath, mutableSetValueForKey, mutableSetValueForKeyPath, observationInfo, observeValueForKeyPathOfObjectChangeContext, performSelector, performSelectorInBackgroundWithObject, performSelectorOnMainThreadWithObjectWaitUntilDone, performSelectorOnMainThreadWithObjectWaitUntilDoneModes, performSelectorOnThreadWithObjectWaitUntilDone, performSelectorOnThreadWithObjectWaitUntilDoneModes, performSelectorWithObject, performSelectorWithObjectAfterDelay, performSelectorWithObjectAfterDelayInModes, performSelectorWithObjectWithObject, prepareForInterfaceBuilder, provideImageDataBytesPerRowOrigin_Size_UserInfo, removeObserverForKeyPath, removeObserverForKeyPathContext, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, self, setAccessibilityActivationPoint, setAccessibilityAttributedHint, setAccessibilityAttributedLabel, setAccessibilityAttributedUserInputLabels, setAccessibilityAttributedValue, setAccessibilityContainerType, setAccessibilityCustomActions, setAccessibilityCustomRotors, setAccessibilityDragSourceDescriptors, setAccessibilityDropPointDescriptors, setAccessibilityElements, setAccessibilityElementsHidden, setAccessibilityFrame, setAccessibilityHint, setAccessibilityLabel, setAccessibilityLanguage, setAccessibilityNavigationStyle, setAccessibilityPath, setAccessibilityRespondsToUserInteraction, setAccessibilityTextualContext, setAccessibilityTraits, setAccessibilityUserInputLabels, setAccessibilityValue, setAccessibilityViewIsModal, setIsAccessibilityElement, setNilValueForKey, setObservationInfo, setShouldGroupAccessibilityChildren, setValueForKey, setValueForKeyPath, setValueForUndefinedKey, setValuesForKeysWithDictionary, shouldGroupAccessibilityChildren, superclass, validateValueForKeyError, validateValueForKeyPathError, valueForKey, valueForKeyPath, valueForUndefinedKey, willChangeValueForKey, willChangeValueForKeyWithSetMutationUsingObjects, willChangeValuesAtIndexesForKeypublic static boolean accessInstanceVariablesDirectly()
public static GCController alloc()
public static GCController allocWithZone(org.moe.natj.general.ptr.VoidPtr zone)
public static boolean automaticallyNotifiesObserversForKey(java.lang.String key)
public static void cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)
public static void cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument)
public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
public static org.moe.natj.objc.Class classForKeyedUnarchiver()
public static NSArray<? extends GCController> controllers()
GCControllerDidConnectNotification,
GCControllerDidDisconnectNotificationpublic static java.lang.String debugDescription_static()
public static java.lang.String description_static()
public static long hash_static()
public static NSObject.Function_instanceMethodForSelector_ret instanceMethodForSelector(org.moe.natj.objc.SEL aSelector)
public static NSMethodSignature instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)
public static boolean instancesRespondToSelector(org.moe.natj.objc.SEL aSelector)
public static boolean isSubclassOfClass(org.moe.natj.objc.Class aClass)
public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey(java.lang.String key)
public static GCController new_objc()
public static boolean resolveClassMethod(org.moe.natj.objc.SEL sel)
public static boolean resolveInstanceMethod(org.moe.natj.objc.SEL sel)
public static void setVersion_static(long aVersion)
public static void startWirelessControllerDiscoveryWithCompletionHandler(GCController.Block_startWirelessControllerDiscoveryWithCompletionHandler completionHandler)
Once discovery has started new controllers will notify themselves as connected via GCControllerDidConnectNotification. As the notification arrives the controller is also available in the controllers array.
The completionHandler could be used to update UI and/or game state to indicate that no more controllers will be found and the current set of controllers is what is available for use in the game.
If a completionHandler was provided, it will be called once when discovery stops. Either from an explicit call to stopWirelessControllerDiscovery or from timing out or stopping in its natural course of operation. Thus the completionHandler will at most be called once per call to startWirelessControllerDiscoveryWithCompletionHandler:.
The completionHandler may also not get called at all, if for example startWirelessControllerDiscoveryWithCompletionHandler: is called multiple times during dicovery. For this case the net effect is that the completionHandler is replaced with each call and only the last one set before discovery stops will be called.
completionHandler - an optional handler that is called when discovery stops. (may be nil, in which case you will not be notified when discovery stops)stopWirelessControllerDiscovery,
controllerspublic static void stopWirelessControllerDiscovery()
startWirelessControllerDiscoveryWithCompletionHandler:public static org.moe.natj.objc.Class superclass_static()
public static long version_static()
public GCController.Block_controllerPausedHandler_ret controllerPausedHandler()
Use this to implement your canonical transition to a pause menu for example if that is your application's desired handling of suspension in play. You may pause and resume based on game state as well so the event is only called each time the pause/resume button is pressed.
[@note] This handler has been deprecated in favor of the Menu button found on GCMicroGamepad and GCExtendedGamepad.
microGamepad,
extendedGamepadpublic GCExtendedGamepad extendedGamepad()
public GCGamepad gamepad()
There are several supported profiles, with an additional optional profile for motion as well. Each controller may be able to map its inputs into all profiles or just one kind of profile. Query for the controller profile that suits your game, the simplest kind will be supported by the broadest variety of controllers. A controller supporting the Extended Gamepad profile for example supports the Gamepad profile and more. As such it can always be used just in the Gamepad profile if that suits the game.
A physical controller that supports a profile must support it completely. That means that all buttons and axis inputs must be valid inputs that a developer can utilize.
If a controller does not support the given profile the returned value will be nil. Use this to filter controllers if the application requires a specific kind of profile.
motionpublic NSObject handlerQueue()
GCDevicehandlerQueue in interface GCDeviceGCControllerAxisInput.valueChangedHandler,
GCControllerButtonInput.valueChangedHandler,
GCControllerButtonInput.pressedChangedHandler,
GCControllerDirectionPad.valueChangedHandler,
GCMotion.valueChangedHandlerpublic GCController init()
public boolean isAttachedToDevice()
public GCMicroGamepad microGamepad()
public GCMotion motion()
gamepad,
extendedGamepadpublic long playerIndex()
This can be set both for the application to keep track of controllers and as a signal to make a controller display a player index on a set of LEDs or some other mechanism.
A controller is not guaranteed to have a visual display of the playerIndex, playerIndex does not persist for a controller with regards to a system.
Negative values less than GCControllerPlayerIndexUnset will just map back to GCControllerPlayerIndexUnset when read back.
public void setControllerPausedHandler(GCController.Block_setControllerPausedHandler value)
Use this to implement your canonical transition to a pause menu for example if that is your application's desired handling of suspension in play. You may pause and resume based on game state as well so the event is only called each time the pause/resume button is pressed.
[@note] This handler has been deprecated in favor of the Menu button found on GCMicroGamepad and GCExtendedGamepad.
microGamepad,
extendedGamepadpublic void setHandlerQueue(NSObject value)
GCDevicesetHandlerQueue in interface GCDeviceGCControllerAxisInput.valueChangedHandler,
GCControllerButtonInput.valueChangedHandler,
GCControllerButtonInput.pressedChangedHandler,
GCControllerDirectionPad.valueChangedHandler,
GCMotion.valueChangedHandlerpublic void setPlayerIndex(long value)
This can be set both for the application to keep track of controllers and as a signal to make a controller display a player index on a set of LEDs or some other mechanism.
A controller is not guaranteed to have a visual display of the playerIndex, playerIndex does not persist for a controller with regards to a system.
Negative values less than GCControllerPlayerIndexUnset will just map back to GCControllerPlayerIndexUnset when read back.
public java.lang.String vendorName()
GCDevicevendorName in interface GCDevicepublic GCController capture()
If your application is heavily multithreaded this may also be useful to guarantee atomicity of input handling as a snapshot will not change based on user input once it is taken.
snapshotpublic static GCController controllerWithExtendedGamepad()
This controller will be considered a snapshot, allowing developers to write to any GCControllerElement of its profiles.
snapshotpublic static GCController controllerWithMicroGamepad()
This controller will be considered a snapshot, allowing developers to write to any GCControllerElement of its profiles.
snapshotpublic boolean isSnapshot()
controllerWithMicroGamepad,
controllerWithExtendedGamepad,
capturepublic java.lang.String productCategory()
GCDeviceproductCategory in interface GCDeviceGCProductCategories.hpublic GCDeviceBattery battery()
This property is useful when you try to notify your user to change or charge controller before it runs out of battery life or simply display the current battery level and status.
public static GCController current()
[@note] This is useful for single player games where you only care about whether an input is pressed, and not where it came from. You will still need to register for changes to GCController.current so that your UI can remain up-to-date with the current controller.
public GCDeviceHaptics haptics()
Use this property to create CHHapticEngine instances according to your needs.
[@note] Haptics are a drain on the controller's battery, and can be distracting when used excessively.
public GCDeviceLight light()
A controller's light can be used to signal information to the player, such as using different light colors based on the player index. It can also be used to react to in-game events and enhance user immersion.
public GCPhysicalInputProfile physicalInputProfile()
GCDevice[@note] This is equivalent to the controller's gamepad, microGamepad, or extendedGamepad instance.
physicalInputProfile in interface GCDeviceGCController.gamepad,
GCController.microGamepad,
GCController.extendedGamepadpublic static void setShouldMonitorBackgroundEvents(boolean value)
[@example] If shouldMonitorBackgroundEvents is NO, and the application is not the frontmost application, any inputs from a game controller will not be forwarded to the application. Once the application becomes the frontmost application, game controller events will be forwarded.
[@note] Starting with macOS Big Sur 11.3, shouldMonitorBackgroundEvents will be NO by default. For applications built prior to macOS Big Sur 11.3, (or running on devices with an earlier version of macOS), shouldMonitorBackgroundEvents will be YES by default. On iOS and tvOS, this property is ignored.
public static boolean shouldMonitorBackgroundEvents()
[@example] If shouldMonitorBackgroundEvents is NO, and the application is not the frontmost application, any inputs from a game controller will not be forwarded to the application. Once the application becomes the frontmost application, game controller events will be forwarded.
[@note] Starting with macOS Big Sur 11.3, shouldMonitorBackgroundEvents will be NO by default. For applications built prior to macOS Big Sur 11.3, (or running on devices with an earlier version of macOS), shouldMonitorBackgroundEvents will be YES by default. On iOS and tvOS, this property is ignored.