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

Recupera a leitura mais recente do fluxo de entrada que corresponde a um filtro fornecido pelo chamador.

## Sintaxe

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

### Parâmetros

*inputKind*   \_In\_\
Tipo: [GameInputKind](/pt-BR/reference/input/gameinput/enums/gameinputkind)

Um dos valores de enumeração que designa o tipo de dispositivo de entrada em uso, como um controle, teclado, mouse ou gamepad. Os valores de enumeração podem ser combinados para designar vários tipos de entrada. Quando vários tipos de entrada são especificados, todas as leituras que contêm pelo menos um dos tipos de entrada serão correspondidas e retornadas.

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

Um filtro opcional que retorna leituras de um dispositivo específico.

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

A leitura de entrada a ser retornada. Retorna `NULL` em caso de falha.

### Valor retornado

Tipo: HRESULT

Resultado da função.

## Comentários

Essa função é usada para acessar inicialmente o fluxo de entrada. Você pode usar essa função com os métodos `GetNextReading` e `GetPreviousReading` para percorrer o fluxo de entrada sem perder entradas. Como alternativa, você pode continuar chamando `GetCurrentReading` para continuar obtendo a leitura mais atual, se o seu jogo puder tolerar a perda de algumas entradas.

O exemplo de código a seguir demonstra como sondar o estado atual do gamepad.

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

O exemplo de código a seguir demonstra como sondar o estado atual do gamepad de um dispositivo específico.

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

O exemplo de código a seguir demonstra como sondar todos os estados do gamepad de um dispositivo específico.

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

## Requisitos

[Visão geral da API de entrada](/pt-BR/build/core-features/common/input/overviews/input-overview)\
[IGameInput\_GetNextReading](/pt-BR/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading)\
[IGameInput\_GetPreviousReading](/pt-BR/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading)\
[IGameInput](/pt-BR/reference/input/gameinput/interfaces/igameinput/igameinput)

## Histórico de versões

| Versão | Alterações |
| - | - |
| **v0** | Introduzido. |


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