> ## 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::GetCurrentReading

> IGameInput::GetCurrentReading

# IGameInput::GetCurrentReading

從輸入串流擷取符合呼叫端所提供篩選條件的最新讀數。

## 語法

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

### 參數

*inputKind*   \_In\_\
類型：[GameInputKind](/zh-TW/reference/input/gameinput/enums/gameinputkind)

其中一個列舉值，指定所使用的輸入裝置類型，例如控制器、鍵盤、滑鼠或遊戲台。列舉值可以合併，以指定多種輸入類型。指定多種輸入種類時，任何包含至少一種輸入種類的讀數都會被比對並傳回。

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

選擇性篩選條件，傳回來自特定裝置的讀數。

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

要傳回的輸入讀數。失敗時傳回 `NULL`。

### 傳回值

類型：HRESULT

函式結果。

## 備註

此函式用於初次存取輸入串流。您可以將此函式與 `GetNextReading` 和 `GetPreviousReading` 方法搭配使用，以逐步瀏覽輸入串流而不遺漏輸入。或者，如果您的遊戲可以容許遺漏部分輸入，您也可以繼續呼叫 `GetCurrentReading` 以持續取得最新的讀數。

下列程式碼範例示範如何輪詢目前的遊戲台狀態。

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

void PollGamepadInput() noexcept
{
    Microsoft::WRL::ComPtr<IGameInputReading> reading;

    if (SUCCEEDED(gameInput->GetCurrentReading(
        GameInputKindGamepad,
        nullptr,
        &reading)))
    {
        // Application-specific code to process the reading.
    }
}
```

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

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

void PollGamepadInput() noexcept
{
    Microsoft::WRL::ComPtr<IGameInputReading> reading;

    if (SUCCEEDED(gameInput->GetCurrentReading(
        GameInputKindGamepad,
        gamepad.Get(),
        &reading)))
    {
        // Lock onto the first device we find input from, since this
        // must be the one the player is using (if it's generating input).
        if (!gamepad)
        {
            reading->GetDevice(&gamepad);
        }

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

    else
    {
        // Go back to looking for a device to lock onto, if the previous one is gone.
        gamepad = nullptr;
    }
}
```

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

```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)))
        {
            gamepad.Attach(prevReading->GetDevice());

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

## 需求

[輸入 API 概觀](/zh-TW/build/core-features/common/input/overviews/input-overview)\
[IGameInput\_GetNextReading](/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading)\
[IGameInput\_GetPreviousReading](/zh-TW/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading)\
[IGameInput](/zh-TW/reference/input/gameinput/interfaces/igameinput/igameinput)

## 版本歷程記錄

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


## Related topics

- [IGameInput::GetCurrentReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getcurrentreading.md)
- [IGameInput::GetTemporalReading](/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading.md)
