Is there any way to identify an input device that is connected to PC? (such as gamepad, arcade stick etc)? In Xbox One SDK every device in Windows::Xbox::Input::IController has got his own ID, but Windows::Gaming::Input::IGameController don't have any id fields. How to identify connected devices? How to determine which controller was removed and which one is still active?
In UWP, we can use classes under Windows.Gaming.Input Namespace to detect and track gaming input devices. As you've added gamepad tag in your question, I will use gamepad for example.
To detect and track gamepads, we can use Gamepad Class. The Gamepad class provides a static property, Gamepads, which is a read-only list of gamepads that are currently connected. Please not it is recommended that you maintain your own collection instead of accessing them through the Gamepads
property.
Once we have the collection, we can then use GamepadAdded and GamepadRemoved events to track gamepads. As their names, these two methods are raised when a gamepad is added or removed. The following is a simple sample:
auto myGamepads = ref new Vector<Gamepad^>();
for (auto gamepad : Gamepad::Gamepads)
{
myGamepads->Append(gamepad);
}
Gamepad::GamepadAdded += ref new EventHandler<Gamepad^>(Platform::Object^, Gamepad^ args)
{
myGamepads->Append(args);
}
Gamepad::GamepadRemoved += ref new EventHandler<Gamepad^>(Platform::Object^, Gamepad^ args)
{
unsigned int indexRemoved;
if(myGamepads->IndexOf(args, &indexRemoved))
{
myGamepads->RemoveAt(indexRemoved);
}
}
If you want to determine which controller was removed, I think you can take advantage of the index. For more info, please see Detect and track gamepads.
For other gaming input devices, they are similar to gamepad, you can refer to the documents under Input for games.