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

# IGameInput::GetPreviousReading

> IGameInput::GetPreviousReading

# IGameInput::GetPreviousReading

Retrieves the previous [IGameInputReading](/reference/input/gameinput/interfaces/igameinputreading/igameinputreading) based on a reference reading from an optionally filtered input stream.

## Syntax

```cpp theme={null}
HRESULT GetPreviousReading(
    IGameInputReading* referenceReading,
    GameInputKind inputKind,
    IGameInputDevice* device,
    IGameInputReading** reading
);
```

### Parameters

*referenceReading*   \_In\_\
Type: IGameInputReading\*

The returned `IGameInputReading` interface is read sequentially before this reference reading.

*inputKind*   \_In\_\
Type: [GameInputKind](/reference/input/gameinput/enums/gameinputkind)

Filter for the types of input to pull the previous reading from. The `GameInputKind` interface is a flag variable. You may combine multiple values to filter on multiple constants. When multiple input kinds are specified, any readings that contain at least one of the input kinds will be matched and returned.

*device*   \_In\_opt\_\
Type: IGameInputDevice\*

Filter for the specific device to pull the previous reading from.

*reading*   \_COM\_Outptr\_\
Type: IGameInputReading\*\*

The returned `IGameInputReading` interface that comes sequentially before the `referenceReading` input.

### Return value

Type: HRESULT

Function result.

## Remarks

The [GetNextReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading) and [GetPreviousReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) methods let apps walk through the input history reading by reading.

Returns a `NULL` value and failure `HRESULT` if there is no reading after the `referenceReading`, or if a device filter is provided for a disconnected device, or if too much time has elapsed and reference reading and returned reading have left the input-stream history buffer. The elapsed time error is rare for apps that continuously process input as the input stream maintains a half second of readings from each device in its history buffer.

The following code example demonstrates how to poll for all gamepad states from a specific device.

```cpp theme={null}
Microsoft::WRL::ComPtr<IGameInput> gameInput;
Microsoft::WRL::ComPtr<IGameInputDevice> gamepad;
Microsoft::WRL::ComPtr<IGameInputReading> prevReading;

void PollGamepadInput() noexcept
{
    if (!prevReading)
    {
        if (SUCCEEDED(gameInput->GetCurrentReading(
            GameInputKindGamepad,
            nullptr,
            &prevReading)))
        {
            prevReading->GetDevice(&gamepad);

            // Application-specific code to process the initial reading
        }
    }

    else
    {
        Microsoft::WRL::ComPtr<IGameInputReading> nextReading;
        HRESULT hr = gameInput->GetNextReading(
            prevReading.Get(),
            GameInputKindGamepad,
            gamepad.Get(),
            &nextReading);

        if (SUCCEEDED(hr))
        {
            // Application-specific code to process the next reading

            prevReading = nextReading;
        }

        else if (hr != GAMEINPUT_E_READING_NOT_FOUND)
        {
            gamepad = nullptr;
            prevReading = nullptr;
        }
    }
}
```

## Requirements

[GameInput](/reference/input/gameinput/gameinput_members)\
[Overview of GameInput](/build/core-features/common/input/overviews/input-overview)\
[IGameInput\_GetCurrentReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getcurrentreading)\
[IGameInput\_GetNextReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading)\
[IGameInput](/reference/input/gameinput/interfaces/igameinput/igameinput)

## Version History

| Version | Changes     |
| ------- | ----------- |
| **v0**  | Introduced. |


## Related topics

- [IGameInput::GetCurrentReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getcurrentreading.md)
- [IGameInput::GetNextReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading.md)
- [IGameInput::GetTemporalReading](/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading.md)
- [IGameInputReading::GetMouseState](/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getmousestate.md)
- [IGameInputReading::GetInputKind](/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getinputkind.md)
