[英]How can I detect whether a hardware device has been plugged or unplugged from my PC through USB port
Current effort: 1, hidapi-1.1.jar 2, GetRawInputDeviceList当前努力:1、hidapi-1.1.jar 2、GetRawInputDeviceList
hidapi-1.1.jar is aborted in my app for some reason.由于某种原因,hidapi-1.1.jar 在我的应用程序中中止。
GetRawInputDeviceList isn't stable in Win10 referring https://stackoverflow.com/questions/32419314/getrawinputdevicelist-and-getrawinputdeviceinfo-fail-to-work-in-win10 GetRawInputDeviceList 在 Win10 中不稳定,参考https://stackoverflow.com/questions/32419314/getrawinputdevicelist-and-getrawinputdeviceinfo-fail-to-work-in-win10
I wonder is there any other method to reach my goal?我想知道还有其他方法可以达到我的目标吗? OS is windows, programming language is not limited.
操作系统是windows,编程语言不限。
You can use the hotplug event notification API present in libusb
.您可以使用
libusb
的热插拔事件通知 API。 Documentation is here: http://libusb.sourceforge.net/api-1.0/hotplug.html文档在这里: http : //libusb.sourceforge.net/api-1.0/hotplug.html
In a nutshell, this API lets your program get a callback whenever a device is connected or disconnected, and lets you filter for just the devices you care about (see libusb_hotplug_register_callback
).简而言之,这个 API 允许您的程序在设备连接或断开连接时获得回调,并让您仅过滤您关心的设备(请参阅
libusb_hotplug_register_callback
)。
Note that the hotplug API isn't supported on all OSes;请注意,并非所有操作系统都支持热插拔 API; if it isn't, you will have to fallback to enumerating devices using
libusb_get_device_list
.如果不是,您将不得不回
libusb_get_device_list
使用libusb_get_device_list
枚举设备。
Actually SetupDiGetDeviceInstanceId can be used to monitor it.实际上可以使用SetupDiGetDeviceInstanceId来监控它。 For details, pls refer to https://msdn.microsoft.com/en-us/library/windows/hardware/ff551106(v=vs.85).aspx .
有关详细信息,请参阅https://msdn.microsoft.com/en-us/library/windows/hardware/ff551106(v=vs.85).aspx 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.