> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# IGameInputDevice::GetXInputDeviceIndex

> Gets the XInput user index that's assigned to the input device, if any.

Gets the XInput user index that's assigned to the input device, if any.

## Syntax

```cpp theme={null}
bool GetXInputDeviceIndex(
    uint32_t* index
);
```

### Parameters

*index*   \_Out\_\
Type: uint32\_t\*

Receives the zero-based XInput user index (0 through 3) of the device. If the device doesn't have an XInput user index, this is set to 0.

### Return value

Type: bool

`true` if the device currently has an XInput user index; otherwise, `false`.

## Remarks

The XInput user index is the controller slot that the XInput API uses to identify a controller, which typically corresponds to the player indicator shown on the controller. Use this method to correlate a GameInput device with the controller that the same user index refers to in XInput, for example when migrating a title from XInput to GameInput one controller at a time.

Only devices that are exposed through XInput have a user index. Other devices, such as keyboards, mice, and most HID game controllers, return `false`. Aggregate devices never have an XInput user index. When a device disconnects, its user index is released, and the method returns `false`.

Unlike most device properties, the XInput user index can change while the device is connected. When it changes, GameInput notifies registered device callbacks with the `GameInputDeviceEventXInputIndexUpdated` value of [GameInputDeviceEvent](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/enums/gameinputdeviceevent). Call `GetXInputDeviceIndex` again from the callback to get the new index.

```cpp theme={null}
void CALLBACK OnDeviceEvent(
    GameInputCallbackToken callbackToken,
    void* context,
    GameInputDeviceEvent deviceEvent,
    IGameInputDevice* device) noexcept
{
    if (deviceEvent == GameInputDeviceEventXInputIndexUpdated)
    {
        uint32_t index = 0;
        if (device->GetXInputDeviceIndex(&index))
        {
            // The device is now assigned to XInput user index 'index'.
        }
        else
        {
            // The device no longer has an XInput user index.
        }
    }
}
```

## Requirements

**Header:** GameInput.h

**Library:** gameinput.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## See also

[Overview of GameInput](https://docs.xbox.com/build/core-features/common/input/overviews/input-overview.md)\
[IGameInputDevice](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)\
[GameInputDeviceEvent](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/enums/gameinputdeviceevent)\
[IGameInput::RegisterDeviceCallback](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinput/methods/igameinput_registerdevicecallback.md)

## Version History

| Version | Changes |
| - | - |
| **v4** | Introduced. |


## Related topics

- [IGameInput::RegisterDeviceCallback](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinput/methods/igameinput_registerdevicecallback.md)
- [IGameInputDevice (Interface contents)](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)
- [IGameInputDevice::GetUsage](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getusage.md)
- [IGameInputDevice::GetGamepadInfo](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getgamepadinfo.md)
- [IGameInputDevice::GetTouchSurfaceCount](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_gettouchsurfacecount.md)
