RawGameController
RawGameController
RawGameController
RawGameController
Class
Definition
Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Prerelease APIs are identified by a Prerelease label.
[Contains prerelease APIs.]
Represents any type of game controller.
public : sealed class RawGameController : IGameController, IGameControllerBatteryInfo, IRawGameControllerpublic sealed class RawGameController : IGameController, IGameControllerBatteryInfo, IRawGameControllerPublic NotInheritable Class RawGameController Implements IGameController, IGameControllerBatteryInfo, IRawGameController// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
Remarks
Instances of the RawGameController class cannot be created directly; instead, instances of the class are retrieved through the RawGameController.RawGameControllers property listing all connected game controllers or through the RawGameController.RawGameControllerAdded event.
All inputs available on a RawGameController are exposed as simple arrays of unnamed buttons, switches, and axes. Using this class, you can allow customers to create custom input mappings no matter what type of controller they're using.
You'll need to create these arrays yourself, and then populate them using RawGameController.GetCurrentReading to determine the states of the buttons, switches, and axes. See that function's documentation for more information.
See Raw game controller for information about how to use the RawGameController class.
Properties
AxisCount AxisCount AxisCount AxisCount
The number of axes on the raw game controller.
public : int AxisCount { get; }public int AxisCount { get; }Public ReadOnly Property AxisCount As int// You can use this property in JavaScript.
- Value
- int int int int
The number of axes on the raw game controller.
ButtonCount ButtonCount ButtonCount ButtonCount
The number of buttons on the raw game controller.
public : int ButtonCount { get; }public int ButtonCount { get; }Public ReadOnly Property ButtonCount As int// You can use this property in JavaScript.
- Value
- int int int int
The number of buttons on the raw game controller.
DisplayName DisplayName DisplayName DisplayName
Prerelease.
public : PlatForm::String DisplayName { get; }public string DisplayName { get; }Public ReadOnly Property DisplayName As string// You can use this property in JavaScript.
- Value
- PlatForm::String string string string
| Device family |
Windows 10 Insider Preview (introduced v10.0.16257.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v5)
|
ForceFeedbackMotors ForceFeedbackMotors ForceFeedbackMotors ForceFeedbackMotors
The list of force feedback motors in the raw game controller.
public : IVectorView<ForceFeedbackMotor> ForceFeedbackMotors { get; }public IReadOnlyList<ForceFeedbackMotor> ForceFeedbackMotors { get; }Public ReadOnly Property ForceFeedbackMotors As IReadOnlyList<ForceFeedbackMotor>// You can use this property in JavaScript.
- Value
- IVectorView<ForceFeedbackMotor> IReadOnlyList<ForceFeedbackMotor> IReadOnlyList<ForceFeedbackMotor> IReadOnlyList<ForceFeedbackMotor>
The list of force feedback motors in the raw game controller.
HardwareProductId HardwareProductId HardwareProductId HardwareProductId
The hardware product ID of the raw game controller.
public : ushort HardwareProductId { get; }public ushort HardwareProductId { get; }Public ReadOnly Property HardwareProductId As ushort// You can use this property in JavaScript.
- Value
- ushort ushort ushort ushort
The hardware product ID of the raw game controller.
Examples
The following example checks if the given raw game controller's PID and VID (Product ID and Vendor ID, respectively) match the given PID and VID.
void CheckIfMatch(RawGameController rawGameController, unsigned short pid, unsigned short vid)
{
if ((rawGameController.HardwareProductId == pid) &&
(rawGameController.HardwareVendorId == vid))
{
/* This controller is the type that we're checking for, so we can assign a
specific input mapping. */
}
}
Remarks
If you have a specific controller that you want to support, you can get this value and RawGameController.HardwareVendorId and check that they match the controller. The position of each input in each array that you get from RawGameController.GetCurrentReading is the same for every controller with the same HardwareProductId and HardwareVendorId, so you don't have to worry about your logic potentially being inconsistent among different controllers of the same type.
HardwareVendorId HardwareVendorId HardwareVendorId HardwareVendorId
The hardware vendor ID of the raw game controller.
public : ushort HardwareVendorId { get; }public ushort HardwareVendorId { get; }Public ReadOnly Property HardwareVendorId As ushort// You can use this property in JavaScript.
- Value
- ushort ushort ushort ushort
The hardware vendor ID of the raw game controller.
Remarks
See RawGameController.HardwareProductId for information about how to use this value to support specific types of controllers.
Headset Headset Headset Headset
The audio headset attached to the raw game controller.
public : Headset Headset { get; }public Headset Headset { get; }Public ReadOnly Property Headset As Headset// You can use this property in JavaScript.
Remarks
See Headset for information about programming for headsets.
IsWireless IsWireless IsWireless IsWireless
Gets a value that indicates the wireless state of the raw game controller.
public : PlatForm::Boolean IsWireless { get; }public bool IsWireless { get; }Public ReadOnly Property IsWireless As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean bool bool bool
True if the raw game controller is wireless. Otherwise, false.
NonRoamableId NonRoamableId NonRoamableId NonRoamableId
Prerelease.
public : PlatForm::String NonRoamableId { get; }public string NonRoamableId { get; }Public ReadOnly Property NonRoamableId As string// You can use this property in JavaScript.
- Value
- PlatForm::String string string string
| Device family |
Windows 10 Insider Preview (introduced v10.0.16257.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v5)
|
RawGameControllers RawGameControllers RawGameControllers RawGameControllers
The list of all connected raw game controllers.
public : static IVectorView<RawGameController> RawGameControllers { get; }public static IReadOnlyList<RawGameController> RawGameControllers { get; }Public Static ReadOnly Property RawGameControllers As IReadOnlyList<RawGameController>// You can use this property in JavaScript.
- Value
- IVectorView<RawGameController> IReadOnlyList<RawGameController> IReadOnlyList<RawGameController> IReadOnlyList<RawGameController>
The list of all connected raw game controllers.
Examples
The following example copies all connected raw game controllers into a new collection:
auto myRawGameControllers = ref new Vector<RawGameController^>();
for (auto rawGameController : RawGameController::RawGameControllers)
{
// This code assumes that you're interested in all raw game controllers.
myRawGameControllers->Append(rawGameController);
}
Remarks
RawGameController objects are managed by the system, therefore you don't have to create or initialize them. Instead, you can access connected raw game controllers through this property. Because you might only be interested in some of the connected raw game controllers, we recommend that you maintain your own collection.
SimpleHapticsControllers SimpleHapticsControllers SimpleHapticsControllers SimpleHapticsControllers
Prerelease.
public : IVectorView<SimpleHapticsController> SimpleHapticsControllers { get; }public IReadOnlyList<SimpleHapticsController> SimpleHapticsControllers { get; }Public ReadOnly Property SimpleHapticsControllers As IReadOnlyList<SimpleHapticsController>// You can use this property in JavaScript.
- Value
- IVectorView<SimpleHapticsController> IReadOnlyList<SimpleHapticsController> IReadOnlyList<SimpleHapticsController> IReadOnlyList<SimpleHapticsController>
| Device family |
Windows 10 Insider Preview (introduced v10.0.16257.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v5)
|
SwitchCount SwitchCount SwitchCount SwitchCount
The number of switches on the raw game controller.
public : int SwitchCount { get; }public int SwitchCount { get; }Public ReadOnly Property SwitchCount As int// You can use this property in JavaScript.
- Value
- int int int int
The number of switches on the raw game controller.
User User User User
The user associated with the raw game controller.
public : User User { get; }public User User { get; }Public ReadOnly Property User As User// You can use this property in JavaScript.
Remarks
See Tracking users and their devices for information about how to keep track of users.
Methods
FromGameController(IGameController) FromGameController(IGameController) FromGameController(IGameController) FromGameController(IGameController)
Returns the given game controller as a raw game controller.
public : static RawGameController FromGameController(IGameController gameController)public static RawGameController FromGameController(IGameController gameController)Public Static Function FromGameController(gameController As IGameController) As RawGameController// You can use this method in JavaScript.
- gameController
- IGameController IGameController IGameController IGameController
The game controller to be returned as a raw game controller.
The raw game controller that was returned from the given game controller.
Remarks
This method checks if the provided game controller has a raw game controller implementation, and if so, it returns that implementation. You might use this method if you want to first get the controller as a RawGameController, and then see if it can be used as another type of controller, such as a Gamepad —if so, you can use a default control scheme for that controller type, otherwise you can let the player do their own input mapping.
GetButtonLabel(Int32) GetButtonLabel(Int32) GetButtonLabel(Int32) GetButtonLabel(Int32)
Retrieves the button label for the specified button.
public : GameControllerButtonLabel GetButtonLabel(int buttonIndex)public GameControllerButtonLabel GetButtonLabel(Int32 buttonIndex)Public Function GetButtonLabel(buttonIndex As Int32) As GameControllerButtonLabel// You can use this method in JavaScript.
- buttonIndex
- int Int32 Int32 Int32
The button for which to retrieve the label.
The label for the specified button. If the button label is blank or there is no known label for the controller’s button, then None is returned.
Remarks
Unlike the GetButtonLabel member functions of other classes, such as ArcadeStick.GetButtonLabel, this function takes an integer, rather than an ArcadeStickButtons or other enumeration value. This integer is an index into the buttons array for the raw game controller.
You can create your own buttons array and then populate it with values representing each button's state using RawGameController.GetCurrentReading. See Raw game controller for more information.
GetCurrentReading(Boolean[], GameControllerSwitchPosition[], Double[]) GetCurrentReading(Boolean[], GameControllerSwitchPosition[], Double[]) GetCurrentReading(Boolean[], GameControllerSwitchPosition[], Double[]) GetCurrentReading(Boolean[], GameControllerSwitchPosition[], Double[])
Gets a snapshot of the raw game controller's state.
public : ulong GetCurrentReading(bool[] buttonArray, GameControllerSwitchPosition[] switchArray, double[] axisArray)public ulong GetCurrentReading(Boolean[] buttonArray, GameControllerSwitchPosition[] switchArray, Double[] axisArray)Public Function GetCurrentReading(buttonArray As Boolean[], switchArray As GameControllerSwitchPosition[], axisArray As Double[]) As ulong// You can use this method in JavaScript.
- buttonArray
- bool[] Boolean[] Boolean[] Boolean[]
The button array for the raw game controller to be populated with the current state of each button.
- switchArray
- GameControllerSwitchPosition[] GameControllerSwitchPosition[] GameControllerSwitchPosition[] GameControllerSwitchPosition[]
The switch array for the raw game controller to be populated with the current state of each switch.
- axisArray
- double[] Double[] Double[] Double[]
The axis array for the raw game controller to be populated with the current state of each axis.
The timestamp of when the reading was retrieved from the raw game controller.
Remarks
Unlike the GetCurrentReading member functions of other classes, such as ArcadeStick.GetCurrentReading, RawGameController.GetCurrentReading takes three parameters: the button, switch, and axis arrays of the raw game controller. You create these arrays yourself, with the sizes RawGameController.ButtonCount, RawGameController.SwitchCount, and RawGameController.AxisCount, respectively.
RawGameController.GetCurrentReading populates each of these arrays with the current states of each input. The button array is an array of Booleans, where true means the button is pressed and false means it is not. The switch array is an array of GameControllerSwitchPosition, where the value at each index represents that switch's current position. Finally, the axis array is an array of doubles, where the value at each index (between 0.0 and 1.0) represents the position of that axis.
See Raw game controller for more information about how to read input from a raw game controller.
GetSwitchKind(Int32) GetSwitchKind(Int32) GetSwitchKind(Int32) GetSwitchKind(Int32)
Gets the type of the specified switch on the raw game controller.
public : GameControllerSwitchKind GetSwitchKind(int switchIndex)public GameControllerSwitchKind GetSwitchKind(Int32 switchIndex)Public Function GetSwitchKind(switchIndex As Int32) As GameControllerSwitchKind// You can use this method in JavaScript.
- switchIndex
- int Int32 Int32 Int32
The index in the raw game controller's switch array of the switch whose type you are querying.
The type of the given switch on the raw game controller.
Remarks
This function takes an integer, which is the index in the raw game controller's switch array that points to the switch you want to query. You can create your own switch array and then populate it with values representing each switch's state using RawGameController.GetCurrentReading. See Raw game controller for more information.
TryGetBatteryReport() TryGetBatteryReport() TryGetBatteryReport() TryGetBatteryReport()
Gets information about the raw game controller's current battery state.
public : BatteryReport TryGetBatteryReport()public BatteryReport TryGetBatteryReport()Public Function TryGetBatteryReport() As BatteryReport// You can use this method in JavaScript.
Information about the raw game controller's current battery state.
Events
HeadsetConnected HeadsetConnected HeadsetConnected HeadsetConnected
Signals when a headset is attached to the raw game controller.
public : event TypedEventHandler HeadsetConnected<IGameController, Headset>public event TypedEventHandler HeadsetConnected<IGameController, Headset>Public Event HeadsetConnected<IGameController, Headset>// You can use this event in JavaScript.
Examples
The following example shows how to register a handler for this event. rawGameController is a RawGameController that's connected to the device.
rawGameController.HeadsetConnected += ref new TypedEventHandler<IGameController^, Headset^>(
[] (IGameController^ device, Headset^ headset)
{
// Enable headset capture and playback on this device.
});
Remarks
For more information on detecting, tracking, and using headsets, see Headset.
HeadsetDisconnected HeadsetDisconnected HeadsetDisconnected HeadsetDisconnected
Signals when a headset is disconnected from the raw game controller.
public : event TypedEventHandler HeadsetDisconnected<IGameController, Headset>public event TypedEventHandler HeadsetDisconnected<IGameController, Headset>Public Event HeadsetDisconnected<IGameController, Headset>// You can use this event in JavaScript.
Examples
The following example shows how to register a handler for this event. rawGameController is a RawGameController that's connected to the device.
rawGameController.HeadsetDisconnected += ref new TypedEventHandler<IGameController^, Headset^>(
[] (IGameController^ device, Headset^ headset)
{
// Enable headset capture and playback on this device.
});
Remarks
For more information on detecting, tracking, and using headsets, see Headset.
RawGameControllerAdded RawGameControllerAdded RawGameControllerAdded RawGameControllerAdded
Signals when a new raw game controller is connected.
public : static event EventHandler RawGameControllerAdded<RawGameController>public static event EventHandler RawGameControllerAdded<RawGameController>Public Static Event RawGameControllerAdded<RawGameController>// You can use this event in JavaScript.
Examples
The following example starts tracking a raw game controller that's been added. myRawGameControllers is a Vector<RawGameController^> that contains the raw game controllers that your game is tracking.
RawGameController::RawGameControllerAdded += ref new EventHandler<RawGameController^>(
[] (Platform::Object^, RawGameController^ args)
{
// This code assumes that you're interested in all new raw game controllers.
myRawGameControllers->Append(args);
});
Remarks
To identify controllers that have already been added, you query the list of connected controllers using RawGameController.RawGameControllers. However, because you might only be interested in some of the connected raw game controllers, we recommend that you maintain your own collection instead of accessing them through RawGameControllers.
RawGameControllerRemoved RawGameControllerRemoved RawGameControllerRemoved RawGameControllerRemoved
Signals when a raw game controller is disconnected.
public : static event EventHandler RawGameControllerRemoved<RawGameController>public static event EventHandler RawGameControllerRemoved<RawGameController>Public Static Event RawGameControllerRemoved<RawGameController>// You can use this event in JavaScript.
Remarks
The following example stops tracking a raw game controller that's been removed. myRawGameControllers is a Vector<RawGameController^> that contains the raw game controllers that your game is tracking.
RawGameController::RawGameControllerRemoved +=
ref new EventHandler<RawGameController^>(
[] (Platform::Object^, RawGameController^ args)
{
unsigned int indexRemoved;
if (myRawGameControllers->IndexOf(args, &indexRemoved))
{
myRawGameControllers->RemoveAt(indexRemoved);
}
});
UserChanged UserChanged UserChanged UserChanged
Signals when the user associated with the raw game controller has changed.
public : event TypedEventHandler UserChanged<IGameController, UserChangedEventArgs>public event TypedEventHandler UserChanged<IGameController, UserChangedEventArgs>Public Event UserChanged<IGameController, UserChangedEventArgs>// You can use this event in JavaScript.
Remarks
See Tracking users and their devices for more information about how to keep track of users.