> ## 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](/reference/input/gameinput/enums/gameinputkind)

コントローラー、キーボード、マウス、またはゲームパッドなど、使用されている入力デバイスの種類を指定する列挙値の 1 つ。列挙値を組み合わせて複数の種類の入力を指定できます。複数の入力種別が指定されている場合、それらの入力種別の少なくとも 1 つを含む読み取り値が一致し、返されます。

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

## 要件

[Input API の概要](/build/core-features/common/input/overviews/input-overview)\
[IGameInput\_GetNextReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading)\
[IGameInput\_GetPreviousReading](/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading)\
[IGameInput](/reference/input/gameinput/interfaces/igameinput/igameinput)

## バージョン履歴

| バージョン  | 変更内容     |
| ------ | -------- |
| **v0** | 導入されました。 |
