c++ - Using DirectInput to receive signal after plugging in joystick -
i have c++ program enumerates input devices (using direct input) @ start of program. if program started, , plug in controller, controller won't recognized until program restarted. know of event can use cause program enumerate of devices after new 1 plugged in?
this article discusses how detect game pad changes. first of all, can handle wm_devicechange
message , check wparam
dbt_devicearrival
or dbt_deviceremovecomplete
. seems in order receive these wparam
s, though, need call registerdevicenotification
first.
the article's example of how follows:
dev_broadcast_deviceinterface notificationfilter; zeromemory(¬ificationfilter, sizeof(notificationfilter)); notificationfilter.dbcc_devicetype = dbt_devtyp_deviceinterface; notificationfilter.dbcc_size = sizeof(notificationfilter); hdevnotify hdevnotify; hdevnotify = registerdevicenotification(m_hwnd, ¬ificationfilter, device_notify_window_handle | device_notify_all_interface_classes); if(hdevnotify == null) { // error handling }
the other thing watch out minimum supported os xp, need put in appropriate #define
before including windows headers.
depending on want do, might not have call function first. instead, can check dbt_devnodes_changed
not differentiate between device being plugged or unplugged. save code if don't care.
Comments
Post a Comment