Share via


LegacyGipGameControllerProvider Class

Definition

Exposes a set of properties and functionality for administering gaming accessories, such as gamepads and headsets, that use the GIP (Gaming Input Protocol) protocol.

Important

Access to this class requires declaring the xboxAccessoryManagement capability

Caution

These APIs affect all games on a system and may cause problems on an accessory if misused. Microsoft recommends only using these APIs for administering hardware you have developed.

public ref class LegacyGipGameControllerProvider sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Gaming.Input.GamingInputPreviewContract, 131072)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class LegacyGipGameControllerProvider final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Gaming.Input.GamingInputPreviewContract), 131072)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class LegacyGipGameControllerProvider
Public NotInheritable Class LegacyGipGameControllerProvider
Inheritance
Object Platform::Object IInspectable LegacyGipGameControllerProvider
Attributes

Windows requirements

Device family
Windows Desktop Extension SDK (introduced in 10.0.23665.0)
API contract
Windows.Gaming.Input.GamingInputPreviewContract (introduced in v2.0)

Examples

Reading the properties of a controller

public void EnumerateControllerProperties()
{
    foreach (Gamepad gamepad in Gamepad.Gamepads)
    {
        // Create the provider
        LegacyGipGameControllerProvider legacyGipGameControllerProvider =
            LegacyGipGameControllerProvider.FromGameController(gamepad);
        if (legacyGipGameControllerProvider == null)
        {
            // Not every gamepad is a legacy GIP game controller, continue enumerating
            continue;
        }

        // Check properties
        GameControllerBatteryChargingState chargeState =
            legacyGipGameControllerProvider.BatteryChargingState;
        GameControllerBatteryKind batteryKind =
            legacyGipGameControllerProvider.BatteryKind;
        GameControllerBatteryLevel batteryLevel =
            legacyGipGameControllerProvider.BatteryLevel;
        bool isOldFirmwareCorrupted =
            legacyGipGameControllerProvider.IsFirmwareCorrupted;
        bool isNewFirmwareCorrupted =
            legacyGipGameControllerProvider.GetDeviceFirmwareCorruptionState()
            != GameControllerFirmwareCorruptReason.NotCorrupt;
        bool isSynthetic = legacyGipGameControllerProvider.IsSyntheticDevice;
        byte[] extendedDeviceInfo = legacyGipGameControllerProvider.GetExtendedDeviceInfo();

        // Check for a particular GIP interface
        bool supportsSomeCustomInterface =
            legacyGipGameControllerProvider.IsInterfaceSupported(
                new Guid(
                    0xaaaaaaaa, 0xbbbb, 0xcccc, 0xe, 0xf, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6));

        IReadOnlyList<string> preferredTypes =
            legacyGipGameControllerProvider.PreferredTypes;
        bool isGamepad = preferredTypes.Contains("Windows.Xbox.Input.Gamepad");
        bool isHeadset = preferredTypes.Contains("Windows.Xbox.Input.Headset");

        // Change the LED to half brightness
        legacyGipGameControllerProvider.SetHomeLedIntensity(50);
    }
}

Remap buttons

void RemapButtons(IGameController controller, IGameControllerProvider controllerProvider)
{
    LegacyGipGameControllerProvider legacyGipGameControllerProvider =
        LegacyGipGameControllerProvider.FromGameControllerProvider(controllerProvider);

    // Retrieve all current remappings set for standard controllers
    IReadOnlyDictionary<RemappingButtonCategory, object> currentMappings =
        legacyGipGameControllerProvider.GetStandardControllerButtonRemapping(
            controller.User, false);

    // Swap two of the buttons
    Dictionary<RemappingButtonCategory, object> remaps =
        new Dictionary<RemappingButtonCategory, object>();

    // Duplicates are not allowed. Swap two of the buttons
    UInt64 currentButtonMappings =
       (UInt64)currentMappings[RemappingButtonCategory.ButtonSettings];

    // Isolate the buttons we want to remap
    UInt64 lastButton = (currentButtonMappings & 0xf000000000000000);
    UInt64 secondLastButton = currentButtonMappings & 0x0f00000000000000;

    // Swap their positions
    UInt64 newMapping = (lastButton >> 4) | (secondLastButton << 4);

    // Recombine with the original mappings
    UInt64 newButtonMappings = (currentButtonMappings & 0x00ffffffffffffff) | newMapping;

    // Add the new button remappings to the mapping dictionary
    remaps.Add(RemappingButtonCategory.ButtonSettings, newButtonMappings);

    // Update controller mapping
    legacyGipGameControllerProvider.SetStandardControllerButtonRemapping(
        controller.User, false, newButtonMappings);
}

Copilot settings

public void CopilotSample(GipGameControllerProvider pilotProvider,
                                    GipGameControllerProvider copilotProvider)
{
    // Establish a copilot pairing for the given pilot and copilot providers
    string pilotId = GameControllerProviderInfo.GetProviderId(pilotProvider);
    string copilotId = GameControllerProviderInfo.GetProviderId(copilotProvider);
    User user = User.GetDefault();
    LegacyGipGameControllerProvider.PairPilotToCopilot(user, pilotId,
        copilotId);

    // Read copilot properties
    LegacyGipGameControllerProvider.IsPilot(user, pilotId); // Returns copilotId
    LegacyGipGameControllerProvider.IsPilot(user, copilotId); // Returns null
    LegacyGipGameControllerProvider.IsCopilot(user, pilotId); // Returns null
    LegacyGipGameControllerProvider.IsCopilot(user, copilotId); // Returns pilotId

    // Removes the pairing for both controllers
    LegacyGipGameControllerProvider.ClearPairing(user, pilotId);
    // Also removes the pairing for both controllers (unnecessary since the pairing was already removed)
    LegacyGipGameControllerProvider.ClearPairing(user, copilotId);
}

Headset management

public void SetupHeadset(IGameControllerProvider headsetProvider)
{
    LegacyGipGameControllerProvider legacyGipGameControllerProvider =
        LegacyGipGameControllerProvider.FromGameControllerProvider(headsetProvider);

    // Reset the device
    legacyGipGameControllerProvider.ExecuteCommand(DeviceCommand.Reset);

    // Check the smart mute level
    byte[] smartMuteBuffer =
        legacyGipGameControllerProvider.GetHeadsetOperation(HeadsetOperation.SmartMute);
    HeadsetLevel smartMuteValue = (HeadsetLevel)smartMuteBuffer[0];

    // Set bass boost to 3db
    byte[] bassBuffer = BitConverter.GetBytes((UInt32)3);
    legacyGipGameControllerProvider.SetHeadsetOperation(HeadsetOperation.BassBoostGain,
        bassBuffer);
}

Properties

AppCompatVersion

Gets the app compat version reported by the GIP (Gaming Input Protocol) driver.

BatteryChargingState

Gets the battery charging state of the controller.

BatteryKind

Gets the controller's battery kind.

BatteryLevel

Gets the battery charge level of the controller.

IsFirmwareCorrupted

Returns whether the controller firmware is corrupted.

IsSyntheticDevice

Returns whether the controller is a synthetic or physical device.

PreferredTypes

Gets the set of GIP (Gaming Input Protocol) types reported by the controller.

Methods

ClearPairing(User, String)

Removes any copilot pairings for controllerId for the given user.

ExecuteCommand(DeviceCommand)

Executes a command on a legacy GIP (Gaming Input Protocol) headset.

FromGameController(IGameController)

Constructs a LegacyGipGameControllerProvider for the given controller.

FromGameControllerProvider(IGameControllerProvider)

Constructs a LegacyGipGameControllerProvider for the given controller provider.

GetDeviceFirmwareCorruptionState()

Retrieves the state of whether the device's firmware is corrupted and if so, in what way.

GetExtendedDeviceInfo()

Retrieves identification information for the device.

GetHeadsetOperation(HeadsetOperation)

Retrieves a headset setting based on operation.

GetStandardControllerButtonRemapping(User, Boolean)

Retrieves the button and axis mapping of a standard gamepad for a user.

IsCopilot(User, String)

Retrieves the ID of the pilot controller if this controller is a copilot.

IsInterfaceSupported(Guid)

Queries whether the given GIP (Gaming Input Protocol) interface guid is supported by the controller.

IsPilot(User, String)

Retrieves the ID of the copilot controller if this controller is a pilot.

PairPilotToCopilot(User, String, String)

Pairs the given pilot and copilot controllers for the given user.

SetHeadsetOperation(HeadsetOperation, Byte[])

Sets a headset operation.

SetHomeLedIntensity(Byte)

Sets the brightness of the LED in the home button of the controller.

SetStandardControllerButtonRemapping(User, Boolean, IMapView<RemappingButtonCategory,Object>)

Changes the button and axis mapping of a standard gamepad for a user.

Applies to

See also