다음을 통해 공유


IGameInput::GetCurrentReading(v2)

호출자 제공 필터와 일치하는 입력 스트림에서 가장 최근의 측정값을 검색합니다.

구문

HRESULT GetCurrentReading(
    GameInputKind inputKind,
    IGameInputDevice* device,
    IGameInputReading** reading
);

매개 변수

inputKind _In_
형식: GameInputKind

컨트롤러, 키보드, 마우스 또는 게임 패드와 같이 사용되는 입력 장치의 유형을 지정하는 열거형 값 중 하나입니다. 열거형 값을 결합하여 여러 입력 유형을 지정할 수 있습니다. 여러 입력 유형이 지정된 경우, 최소 하나 이상의 입력 유형을 포함하는 모든 측정값이 일치하며 반환됩니다.

device _In_opt_
형식: IGameInputDevice*

특정 장치의 판독값을 반환하는 선택적 필터입니다.

읽기 _COM_Outptr_
형식: IGameInputReading**

반환될 입력 측정값입니다. 실패 시 를 반환 NULL 합니다.

반환 값

형식: HRESULT

함수 결과입니다.

비고

이 함수는 입력 스트림을 처음 액세스하는 데 사용됩니다. 이 함수를 GetNextReadingGetPreviousReading 메서드과 함께 사용하여 입력 스트림을 누락되는 입력 없이 차례로 탐색할 수 있습니다. 또는 게임에서 약간의 입력 누락을 허용할 수 있는 경우 GetCurrentReading을(를) 지속적으로 호출하여 최신 측정값을 계속 가져올 수 있습니다.

다음 코드 예제는 현재 게임 패드 상태를 폴링하는 방법을 보여줍니다.

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

다음 코드 예제는 특정 장치에서 현재 게임 패드 상태를 폴링하는 방법을 보여줍니다.

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

다음 코드 예제는 특정 장치에서 모든 게임 패드 상태를 폴링하는 방법을 보여줍니다.

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

요건

헤더: GameInput.h

라이브러리: gameinput.lib

지원되는 플랫폼: Windows

참고 항목

입력 API 개요
IGameInput_GetNextReading
IGameInput_GetPreviousReading
IGameInput