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

# Porting from Windows.XBOX.Input to GameInput

> Porting from Windows.XBOX.Input to GameInput

<a id="introductionSection" />

`Windows.Xbox.Input` is the input API for pre-GDK XBOX One Software Development Kit development. Conceptually, `GameInput` sees devices and input readings in a different way. This topic describes some key differences between `Windows.Xbox.Input` and `GameInput`.

## Input-centric vs. device-centric

The key difference between `Windows.Xbox.Input` and `GameInput` is that the former requires you to start by gathering devices and input state as a property of a device. In contrast, `GameInput` starts with a filterable stream of input readings that have associated devices.

## Looking for the A button press

When a game first launches, often a user must press **A** to signify that they're ready to continue. Here, an example compares doing this in `Windows.Xbox.Input` and `GameInput`. This example looks only for a gamepad. Note that the examples are simplified for demonstration.

### Windows.Xbox.Input

The following code example begins by enumerating all the gamepads that are connected to the system and storing them in the `gamepads` vector. It then iterates through `gamepads` in a loop, looks at each of their current input readings, and checks each reading for **A**.

<Note>This code refers to a previous API. These calls are nonexistent in `GameInput`.</Note>

```c++ theme={null}
void PollGamepadInput()
{
    // Find all gamepads.
    IVectorView<IGamepad^>^ gamepads = Gamepad::GetGamepads();

    // Cycle through each gamepad.
    for ( unsigned int i = 0; i < gamepads->Size; ++i )
    {
        // Get the gamepad's current reading.
        IGamepadReading^ reading = gamepads->GetAt(i)->GetCurrentReading();

        if ( reading->IsAPressed )
        {
            // Logic for the A button being pressed.
        }
    }
}
```

This model could be improved. The game must store copies of the different devices that are connected to the system. You must understand the specifics of each device. Also, by storing a local copy of all the gamepads, the code captures a state in time rather than getting the most up-to-date readings.

### GameInput

In the following code example, the code looks for the most recent gamepad reading from any device. By calling [GetCurrentReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getcurrentreading) with a [GameInputKind](/reference/input/gameinput/enums/gameinputkind) filter set to `GamePad`,  the code asks `m_gameInput` to only return gamepad readings. Next, the code queries the state of the reading and checks for an **A** press.

You might want to keep track of which gamepad you're talking to. For a more complete example, see [GameInput readings](/build/core-features/common/input/overviews/input-readings).

```c++ theme={null}
IGameInput* g_gameInput = nullptr;

HRESULT InitializeInput()
{
    return GameInputCreate(&g_gameInput);
}

void PollGamepadInput()
{
    ComPtr<IGameInputReading> reading;

    // Get the most current gamepad reading, not filtering by a specific device.
    // An error from the GetReading method indicates that no gamepad readings
    // were found.
    if (SUCCEEDED(g_gameInput->GetCurrentReading(GameInputKindGamepad, nullptr, &reading)))
    {
        // Read the gamepad state.
        GameInputGamepadState state;
        reading->GetGamepadState(&state);

        if (state.buttons & GameInputGamepadA)
        {
            // Logic for the A button being pressed.
        }
    }
}
```

<Note>`GameInput` doesn't require that you iterate through devices and check each reading. Instead, you can check with one method call for the latest state of input. You can choose how much or how little you want to know about each physical device.</Note>

<a id="seeAlsoSection" />

## Reference API documentation

* [GameInput (API contents)](/reference/input/gameinput/gameinput_members)

## See also

[GameInput overview](/build/core-features/common/input/overviews/input-overview)

[Input API reference](/reference/input/gc-reference-input-toc)

[Microsoft Game Development Kit](/services/playfab/sdks/platforms/gdk)


## Related topics

- [Combining GameInput with existing input stacks](/build/core-features/common/input/porting/input-porting.md)
- [Porting existing input code to GameInput](/build/core-features/common/input/porting/index.md)
- [Porting guides to the XBOX GDK](/home/build-first-title/porting-guides.md)
- [Overview of GameInput](/build/core-features/common/input/overviews/input-overview.md)
- [Porting from XInput to GameInput](/build/core-features/common/input/porting/input-porting-xinput.md)
