다음을 통해 공유


IGameInput::RegisterReadingCallback(v0)

참고 항목

이 기능은 아직 구현되지 않았습니다.

입력 스트림에서 새 수치가 도착할 때 호출할 함수를 등록합니다.

구문

HRESULT RegisterReadingCallback(  
         IGameInputDevice* device,  
         GameInputKind inputKind,  
         float analogThreshold,  
         void* context,  
         GameInputReadingCallback callbackFunc,  
         GameInputCallbackToken* callbackToken  
)  

매개 변수

device _In_opt_
형식: IGameInputDevice*

등록된 콜백이 특정 장치에 대해서만 트리거되도록 제한합니다.

inputKind _In_
형식: GameInputKind

등록된 콜백이 지정된 입력 유형 중 하나 이상을 지원하는 장치에 대해서만 트리거되도록 제한합니다.

analogThreshold _In_
형식: float

콜백을 트리거하려면 수치 내의 하나 이상의 아날로그 값에서 필요한 최소 델타를 지정합니다.

context _In_opt_
형식: void*

콜백 함수에 대해 관련 정보를 제공하는 일부 개체입니다. 일반적으로 호출 개체입니다.

callbackFunc _In_
형식: GameInputReadingCallback

타이틀에 정의된 콜백 함수입니다.

callbackToken _Result_zeroonfailure_
형식: GameInputCallbackToken*

등록된 콜백 함수를 식별하는 토큰입니다. 이 토큰은 콜백 함수를 취소하거나 등록 취소하려는 이벤트에서 등록된 함수를 식별하기 위해 사용됩니다.

반환 값

형식: HRESULT

이 기능은 아직 구현되지 않았습니다. E_NOTIMPL을 반환합니다.

비고

콜백을 등록해도 최근 읽기가 제공된 입력 필터와 일치하는 초기 콜백이 디스패치되지 않습니다. 이후의 상태 변화 시에만 콜백이 전달됩니다.

다음 C++ 샘플은 특정 장치에서 이벤트 기반 게임 패드 상태를 가져오는 방법을 보여줍니다.

Microsoft::WRL::ComPtr<IGameInput> gameInput; 
Microsoft::WRL::ComPtr<IGameInputReading> prevReading; 
 
void CALLBACK OnGamepadReading( 
    _In_ GameInputCallbackToken callbackToken, 
    _In_ void * context, 
    _In_ uint64_t timestamp, 
    _In_ IGameInputDevice * device, 
    _In_ IGameInputReading * reading, 
    _In_ bool hasOverrunOccurred) 
{ 
    if (prevReading && !hasOverrunOccurred) 
    { 
        // Application-specific code to process the 
        // deltas between 'reading' and 'prevReading' 
    } 
 
    else 
    { 
        // Application-specific code to process the 
        // reading as an initial (standalone) reading 
    } 
 
    prevReading = reading; 
} 
 
void WaitForReadingsWorker( 
    _In_ AsyncQueueHandleT queue, 
    _In_ IGameInputDevice * gamepad, 
    _In_ volatile bool & cancelWait) noexcept 
{ 
    bool enumerationComplete = false; 
    GameInputCallbackToken token; 
    if (SUCCEEDED(gameInput->RegisterReadingCallback( 
        queue, 
        GameInputKindGamepad, 
        gamepad, 
        0.0, 
        nullptr, 
        OnGamepadReading, 
        &token))) 
    { 
        while (!cancelWait) 
        { 
            DispatchAsyncQueue(queue, AsyncQueueCallbackType_Completion, 100); 
        } 
 
        gameInput->UnregisterCallback(token, 5000); 
    } 
} 

다음 C++ 샘플에서는 이벤트를 사용하여 작업 매핑 UI에 대한 게임 패드 및 키보드의 입력을 모니터링하는 방법을 보여 줍니다.

Microsoft::WRL::ComPtr<IGameInput> gameInput; 
Microsoft::WRL::ComPtr<IGameInputReading> initialReading; 
Microsoft::WRL::ComPtr<IGameInputReading> changedReading; 
Microsoft::WRL::ComPtr<IGameInputDevice> changedDevice; 
 
void CALLBACK OnReading( 
    _In_ GameInputCallbackToken callbackToken, 
    _In_ void * context, 
    _In_ uint64_t timestamp, 
    _In_ IGameInputDevice * device, 
    _In_ IGameInputReading * reading, 
    _In_ bool hasOverrunOccurred) 
{ 
    if (SUCCEEDED(gameInput->GetPreviousReading( 
        reading, 
        GameInputKindGamepad | GameInputKindKeyboard, 
        device, 
        &initialReading))) 
    { 
        changedDevice = device; 
        changedReading = reading; 
    } 
} 
 
bool WaitForAnyInput( 
    _In_ AsyncQueueHandleT queue, 
    _In_ uint32_t timeout, 
    _In_ float analogThreshold) noexcept 
{ 
    bool inputFound = false; 
 
    GameInputCallbackToken token; 
    if (SUCCEEDED(gameInput->RegisterReadingCallback( 
        queue, 
        GameInputKindGamepad | GameInputKindKeyboard, 
        nullptr, 
        analogThreshold, 
        nullptr, 
        OnReading, 
        &token))) 
    { 
        inputFound = DispatchAsyncQueue( 
            queue, 
            AsyncQueueCallbackType_Completion, 
            timeout); 
 
        gameInput->UnregisterCallback(token, 5000); 
    } 
 
    return inputFound; 
} 

요구 사항

헤더: GameInput.h

라이브러리: xgameruntime.lib

지원되는 플랫폼: Windows, Xbox One 패밀리 콘솔 및 Xbox Series 콘솔

참고 항목

입력 API 개요
IGameInput
IGameInput::UnregisterCallback
IGameInput::StopCallback