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

# IGameInput::GetPreviousReading

> IGameInput::GetPreviousReading

# IGameInput::GetPreviousReading

根據參考讀數，從可選擇性篩選的輸入串流中擷取前一個 [IGameInputReading](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputreading/igameinputreading.md)。

## 語法

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

### 參數

*referenceReading*   \_In\_\
類型：IGameInputReading\*

傳回的 `IGameInputReading` 介面在順序上會在此參考讀數之前讀取。

*inputKind*   \_In\_\
類型：[GameInputKind](https://docs.xbox.com/zh-TW/reference/input/gameinput/enums/gameinputkind.md)

用來篩選要從中擷取前一個讀數的輸入類型。`GameInputKind` 介面是旗標變數。您可以結合多個值，以依多個常數進行篩選。指定多個輸入類型時，任何至少包含其中一種輸入類型的讀數都會被比對並傳回。

*device*   \_In\_opt\_\
類型：IGameInputDevice\*

用來篩選要從中擷取前一個讀數的特定裝置。

*reading*   \_COM\_Outptr\_\
類型：IGameInputReading\*\*

傳回的 `IGameInputReading` 介面，在順序上位於 `referenceReading` 輸入之前。

### 傳回值

類型：HRESULT

函式結果。

## 備註

[GetNextReading](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading.md) 和 [GetPreviousReading](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading.md) 方法可讓應用程式逐一讀數地瀏覽輸入歷程記錄。

如果 `referenceReading` 之後沒有讀數、針對已中斷連線的裝置提供了裝置篩選條件，或經過太長時間而使參考讀數與傳回的讀數已離開輸入串流歷程記錄緩衝區，則會傳回 `NULL` 值和失敗的 `HRESULT`。對於持續處理輸入的應用程式而言，經過時間的錯誤很少發生，因為輸入串流會在其歷程記錄緩衝區中保留每個裝置半秒的讀數。

下列程式碼範例示範如何輪詢特定裝置的所有遊戲台狀態。

```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;
        }
    }
}
```

## 需求

[GameInput](https://docs.xbox.com/zh-TW/reference/input/gameinput/gameinput_members.md)\
[GameInput 概觀](https://docs.xbox.com/zh-TW/build/core-features/common/input/overviews/input-overview.md)\
[IGameInput\_GetCurrentReading](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getcurrentreading.md)\
[IGameInput\_GetNextReading](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading.md)\
[IGameInput](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinput/igameinput.md)

## 版本歷程記錄

| 版本 | 變更 |
| - | - |
| **v0** | 已推出。 |


## Related topics

- [IGameInput::GetCurrentReading](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getcurrentreading.md)
- [IGameInput::GetNextReading](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading.md)
- [IGameInput::GetTemporalReading (已淘汰)](https://docs.xbox.com/zh-TW/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading.md)
- [IGameInputReading::GetTouchCount (已淘汰)](https://docs.xbox.com/zh-TW/reference/input/gameinput/deprecated/interfaces/igameinputreading/methods/igameinputreading_gettouchcount.md)
- [IGameInputReading::GetTouchState (已淘汰)](https://docs.xbox.com/zh-TW/reference/input/gameinput/deprecated/interfaces/igameinputreading/methods/igameinputreading_gettouchstate.md)
