Win32 determining when keyboard is connected/disconnected

前端 未结 1 749
死守一世寂寞
死守一世寂寞 2021-01-05 20:18

I am trying to determine when my keyboard is connected or disconnected. I have tried the following strategies:

RegisterDeviceNotification

U

相关标签:
1条回答
  • 2021-01-05 21:05

    Have you considered GetRawInputDeviceList() and GetRawInputDeviceInfo(), using RID_DEVICE_INFO for pData and checking it's dwType?

    That will get you the initial state, then if your wndProc handles WM_INPUT_DEVICE_CHANGE you can use the params to detect add/remove, and the lParam can be sent straigth to GetRawInputDeviceInfo().

    Per comments: The WM_INPUT_DEVICE_CHANGE will only arrive for apps that have called RegisterRawInputDevices() and specifically asked for this notification.

    0 讨论(0)
提交回复
热议问题