This isn’t a patch and actually contains no SDL code at all, but it
should be useful to anyone who wants to implement hotplug support for
SDL on Windows.
I’ve figured out a method to detect when devices are plugged in or
removed on Windows XP.
If someone has a better way, please reply.
I would just use WM_INPUT_DEVICE_CHANGE, but it only works on Vista and up.
WM_DEVICECHANGE is really designed mainly for storage devices with
removable media, so DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
aren’t so useful as one might expect either, but Windows does send a
WM_DEVICECHANGE message with an undocumented wParam of 0x0007 whenever
a USB device is inserted or removed. If you wait a bit after
receiving this message (quarter second works), then call
GetRawInputDeviceList(), you can get an up to date list of available
input devices. If a device is unplugged, then plugged back in, you
can check if it’s the same device by comparing the device name
returned by GetRawInputDeviceInfo() (with RIDI_DEVICENAME as the
second parameter).
Of course, you could just poll using GetRawInputDeviceList(), but
would be quite a bit slower.
Source attached for test program. Run it and plug or unplug a USB
mouse, joystick or keyboard to see what happens.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: main.cpp
Type: application/octet-stream
Size: 8587 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090906/4d2de950/attachment.obj