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