Delen via


RawGameController Class

Definition

Represents any type of game controller.

public ref class RawGameController sealed : IGameControllerBatteryInfo
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 262144)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class RawGameController final : IGameControllerBatteryInfo
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 262144)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class RawGameController : IGameControllerBatteryInfo
Public NotInheritable Class RawGameController
Implements IGameControllerBatteryInfo
Inheritance
Object Platform::Object IInspectable RawGameController
Attributes
Implements

Windows requirements

Device family
Windows 10 Creators Update (introduced in 10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v4.0)

Examples

The following code snippet shows how to loop through the RawGameController.RawGameControllers list and add each RawGameController to a vector. You'll need to put a lock on the vector, because things can change at any time (a controller might be disconnected or reconnected, for example).

#include <concrt.h>
#include <winrt/Windows.Gaming.Input.h>
using namespace winrt;
using namespace Windows::Gaming::Input;
...
std::vector<RawGameController> myRawGameControllers;
concurrency::critical_section myLock{};

for (auto const& rawGameController : RawGameController::RawGameControllers())
{
    // Test whether the raw game controller is already in myRawGameControllers; if it isn't, add it.
    concurrency::critical_section::scoped_lock lock{ myLock };
    auto it{ std::find(begin(myRawGameControllers), end(myRawGameControllers), rawGameController) };

    if (it == end(myRawGameControllers))
    {
        // This code assumes that you're interested in all raw game controllers.
        myRawGameControllers.push_back(rawGameController);
    }
}

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 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.

Version history

Windows version SDK version Value added
1709 16299 DisplayName
1709 16299 NonRoamableId
1709 16299 SimpleHapticsControllers

Properties

AxisCount

The number of axes on the raw game controller.

ButtonCount

The number of buttons on the raw game controller.

DisplayName

The name of the controller, provided by the hardware.

ForceFeedbackMotors

The list of force feedback motors in the raw game controller.

HardwareProductId

The hardware product ID of the raw game controller.

HardwareVendorId

The hardware vendor ID of the raw game controller.

Headset

The audio headset attached to the raw game controller.

IsWireless

Gets a value that indicates the wireless state of the raw game controller.

NonRoamableId

A unique ID that identifies the controller. As long as the controller is connected, the ID will never change.

RawGameControllers

The list of all connected raw game controllers.

SimpleHapticsControllers

A collection of SimpleHapticsController objects representing all available haptic feedback motors available on the device.

SwitchCount

The number of switches on the raw game controller.

User

The user associated with the raw game controller.

Methods

FromGameController(IGameController)

Returns the given game controller as a raw game controller.

GetButtonLabel(Int32)

Retrieves the button label for the specified button.

GetCurrentReading(Boolean[], GameControllerSwitchPosition[], Double[])

Gets a snapshot of the raw game controller's state.

GetSwitchKind(Int32)

Gets the type of the specified switch on the raw game controller.

TryGetBatteryReport()

Gets information about the raw game controller's current battery state.

Events

HeadsetConnected

Signals when a headset is attached to the raw game controller.

HeadsetDisconnected

Signals when a headset is disconnected from the raw game controller.

RawGameControllerAdded

Signals when a new raw game controller is connected.

RawGameControllerRemoved

Signals when a raw game controller is disconnected.

UserChanged

Signals when the user associated with the raw game controller has changed.

Applies to

See also