IGameInput::GetCurrentReading
呼び出し元が指定したフィルターに一致する最新の読み取り値を入力ストリームから取得します。
構文
HRESULT GetCurrentReading(
GameInputKind inputKind,
IGameInputDevice* device,
IGameInputReading** reading
)
パラメーター
inputKind _In_
型: GameInputKind
コントローラー、キーボード、マウス、ゲームパッドなど、使用されている入力デバイスの種類を指定する列挙値の 1 つ。 列挙値を組み合わせて複数の入力の種類を指定できます。 複数の入力の種類を指定すると、入力の種類の 1 つ以上が含まれている読み取り値がすべて一致し、返されます。
device _In_opt_
型: IGameInputDevice*
特定のデバイスからの読み取り値を返すオプションのフィルター。
reading _COM_Outptr_
型: IGameInputReading**
返される入力の読み取り値。 失敗した場合は NULL を返します。
戻り値
型: HRESULT
関数の結果です。
解説
この関数を使用して、最初に入力ストリームにアクセスします。 この関数を GetNextReading
および GetPreviousReading
メソッドと共に使用して、入力の欠落がない入力ストリームをたどることができます。 または、ゲームで入力の欠落をある程度許容できる場合は、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
ライブラリ: xgameruntime.lib
サポートされているプラットフォーム: Windows、Xbox One ファミリー本体、Xbox Series 本体
関連項目
入力 API の概要
IGameInput_GetNextReading
IGameInput_GetPreviousReading
IGameInput