시스템에서 장치가 연결되거나 연결 해제될 때마다 호출되도록 GameInputDeviceCallback 함수를 등록합니다. 또한 장치 속성이 변경될 때에도 함수를 호출할 수 있습니다.
구문
HRESULT RegisterDeviceCallback(
IGameInputDevice* device,
GameInputKind inputKind,
GameInputDeviceStatus statusFilter,
GameInputEnumerationKind enumerationKind,
void* context,
GameInputDeviceCallback callbackFunc,
GameInputCallbackToken* callbackToken
)
매개 변수
device _In_opt_
형식: IGameInputDevice*
등록된 콜백이 특정 장치에 대해서만 트리거되도록 제한합니다.
inputKind _In_
형식: GameInputKind
등록된 콜백이 지정된 입력 유형 중 하나 이상을 지원하는 장치에 대해서만 트리거되도록 제한합니다.
statusFilter _In_
형식: GameInputDeviceStatus
등록된 콜백이 특정 유형의 장치 상태 변경에 대해서만 트리거되도록 제한합니다.
enumerationKind _In_
형식: GameInputEnumerationKind
장치가 열거되는지 여부를 확인하고 열거가 완료될 때까지 함수가 대기하는지 여부를 확인합니다.
context _In_opt_
형식: void*
콜백 함수에 대해 관련 정보를 제공하는 일부 개체입니다. 일반적으로 호출 개체입니다.
callbackFunc _In_
형식: GameInputDeviceCallback
장치 연결 또는 연결 해제 이벤트 시에 등록할 타이틀 정의 콜백입니다.
callbackToken _Result_zeroonfailure_
형식: GameInputCallbackToken*
등록된 콜백 함수를 식별하는 토큰입니다. 이 토큰은 콜백 함수를 취소하거나 등록을 취소하려는 이벤트에 등록된 함수를 식별하기 위해 사용됩니다.
반환 값
형식: HRESULT
함수 결과입니다.
비고
IIGameInput::RegisterDeviceCallback으로 등록된 함수를 사용하여 연결 또는 연결 해제와 같은 일반적인 것부터 유선 및 연결된 입력 사이의 전환과 같은 보다 특수한 것까지 장치의 상태 변화에 대응할 수 있습니다. 인식할 수 있는 상태 변화 유형은 GameInputDeviceStatus에 나열되어 있습니다.
enumerationKind 매개 변수는 시스템에 연결된 각 장치에 대한 콜백의 초기 salvo를 생성하는 데 사용할 수 있습니다. 이 초기 열거형을 비동기 또는 동기 열거로 설정할 수 있습니다. 동기 열거는 IGameInput::RegisterDeviceCallback 반환 이전에 모든 초기 콜백을 호출합니다.
다음 C++ 샘플은 연결된 게임 패드 및 키보드를 명시적으로 열거하는 방법을 보여줍니다.
Microsoft::WRL::ComPtr<IGameInput> gameInput;
void CALLBACK OnDeviceEnumerated(
_In_ GameInputCallbackToken callbackToken,
_In_ void * context,
_In_ IGameInputDevice * device,
_In_ uint64_t timestamp,
_In_ GameInputDeviceStatus currentStatus,
_In_ GameInputDeviceStatus previousStatus)
{
// Application-specific code to handle the enumerated device
}
void EnumerateDevicesWorker() noexcept
{
GameInputCallbackToken token;
if (SUCCEEDED(gameInput->RegisterDeviceCallback(
nullptr, // Don't filter to events from a specific device
GameInputKindGamepad | GameInputKindKeyboard, // Enumerate gamepads and keyboards
GameInputDeviceAnyStatus, // Any device status
GameInputBlockingEnumeration, // Enumerate synchronously
nullptr, // No callback context parameter
OnDeviceEnumerated, // Callback function
&token))) // Generated token
{
gameInput->UnregisterCallback(token, 5000);
}
}
다음 C++ 샘플은 장치가 연결 또는 연결 해제될 때 알림을 제공하는 방법을 보여줍니다.
Microsoft::WRL::ComPtr<IGameInput> gameInput;
void CALLBACK OnDeviceConnectionChanged(
_In_ GameInputCallbackToken callbackToken,
_In_ void * context,
_In_ IGameInputDevice * device,
_In_ uint64_t timestamp,
_In_ GameInputDeviceStatus currentStatus,
_In_ GameInputDeviceStatus previousStatus,
)
{
if (currentStatus & GameInputDeviceConnected)
{
// Application-specific code to handle the device connection
}
else
{
// Application-specific code to handle the device disconnection
}
}
void MonitorDeviceConnectionChanges(
_In_ volatile bool & cancelMonitoring) noexcept
{
GameInputCallbackToken token;
if (SUCCEEDED(gameInput->RegisterDeviceCallback(
nullptr, // Don't filter to events from a specific device
GameInputKindGamepad | GameInputKindKeyboard, // Listen for Gamepad and Keyboard changes
GameInputDeviceConnected, // Notify on changes to GameInputDeviceConnected status
GameInputAsyncEnumeration, // Enumerate initial devices asynchronously
nullptr, // No callback context parameter
OnDeviceConnectionChanged, // Callback function
&token))) // Generated token
{
while (!cancelMonitoring)
{
Sleep(100);
}
gameInput->UnregisterCallback(token, 5000);
}
}
요건
헤더: GameInput.h
라이브러리: xgameruntime.lib
지원되는 플랫폼: Windows, Xbox One 패밀리 콘솔 및 Xbox Series 콘솔
참고 항목
입력 API 개요
IGameInput
IGameInput::UnregisterCallback
IGameInput::StopCallback