基于参考读取从可选的已筛选输入流中检索下一个可用 IGameInputReading 接口。
语法
HRESULT GetNextReading(
IGameInputReading* referenceReading,
GameInputKind inputKind,
IGameInputDevice* device,
IGameInputReading** reading
);
参数
referenceReading _In_
类型:IGameInputReading*
当前 IGameInputReading。 返回的 IGameInputReading 接口是此参考读取后下一个读取的对象。
inputKind _In_
类型:GameInputKind
要从中提取下一个读取的输入类型的筛选器。
GameInputKind 界面是一个标志变量。 可以组合多个值以对多个 GameInputKind 常量进行筛选。 在指定多种输入类型时,将匹配并返回包含至少一种输入类型的任何读取。
device _In_opt_
类型:IGameInputDevice*
筛选要从中拉取下一个读取的特定设备。
reading _COM_Outptr_
类型:IGameInputReading**
在 referenceReading 输入之后按顺序显示的返回的 IGameInputReading 接口。
返回值
类型:HRESULT
函数结果。
备注
GetNextReading 和 GetPreviousReading 方法使应用能够通过读取遍历输入历史记录。
如果在 referenceReading 后没有任何读取,或者为断开连接的设备提供了设备筛选器,或者在经过了过长的时间后参考读取和返回的读取仍保留在输入流历史记录缓冲区,则返回 NULL 值和失败 HRESULT。 对于持续不断处理输入的应用而言,上述经过了过长时间的错误十分罕见,因为输入流会在其历史记录缓冲区中保持每个设备半秒钟的读取。
以下代码示例演示了如何从某一特定设备轮询所有游戏板状态。
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)))
{
prevReading->GetDevice(&gamepad);
// 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
支持的平台: 窗户
另请参阅
GameInputIGameInput_GetCurrentReading IGameInput_GetPreviousReadingIGameInput 概述