本文介绍了SWT:系统设备更改通知(USB设备连接/断开连接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个需要坐在系统托盘中的SWT应用程序,并在用户连接一些USB设备时自动弹出(应用程序作为其控制面板)。

I'm writing an SWT application which needs to sit in the system tray and pop up automatically whenever the user connects some USB device (the application serves as its control panel).

在本地环境中执行此操作的方式(在这种情况下为win32,但我最终应该是平台无关)是监听WM_DEVICECHANGE事件,然后检查我的设备是否已断开连接。

The way to do this in the native environment (win32 in this case, but I should be platform-independent ultimately) is to listen to the WM_DEVICECHANGE event, then checking if my device has been disconnected.

搜索主题,似乎SWT实际上并不处理这种类型的事件。有谁有任何想法如何实现这一点?我的后备解决方案将每n秒采样USB端口,寻找该设备,但这是一个不需要的解决方案,只要我关心...

Googling the subject, it seems like SWT does not in fact handle this type of event. Does anyone have any idea as to how to achieve this? My fallback solution would be sampling the USB port every n seconds, looking for the device, but this is a no-no solution as far as I'm concerned...

感谢和欢呼

Shai

推荐答案

编辑: J-16 SDiZ报告说,API也存在于Windows

这是一篇很好的文章,关于

Here is a very good article about Access USB devices from Java applications

描述的jUSB模块包含对象。

The described jUSB module contains a USBListener object.

Youre SWt对象可以实现此侦听器并执行某些操作,当方法

Youre SWt object can implement this listener and do something, when the method

deviceAdded(Device dev)

被触发

这篇关于SWT:系统设备更改通知(USB设备连接/断开连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:06