gpt4 book ai didi

java - 如何知道连接到系统的输入设备是什么

转载 作者:行者123 更新时间:2023-11-30 09:27:54 25 4
gpt4 key购买 nike

我只是想知道连接到系统的输入设备和输出设备是什么。是否有任何api可以使用java获取有关输入/输出设备的信息?

编辑

独立于任何操作系统。

请提出建议。

最佳答案

要查找连接到系统的 USB 设备,您可以使用 jUSB .这article有关于如何使用 api 的更深入的信息。特别是要查找所有 USB 设备(根据文章稍作修改):

Host host = HostFactory.getHost();
// Obtain a list of the USB buses available on the Host.
Bus[] bus = host.getBusses();

// Traverse through all the USB buses.
for (int i = 0; i < bus.length; i++) {
// Access the root hub on the USB bus and obtain the number of USB ports available on the root hub.
Device root = bus[i].getRootHub();
int totalPorts = root.getNumPorts();

// Traverse through all the USB ports available on the
// root hub. It should be mentioned that the numbering
// starts from 1, not 0.
for (int j=1; j<=total_port; j++) {
// Obtain the Device connected to the port.
Device device = root.getChild(j);
if (device != null) {
// USB device available, do something here.
}
}
}

同样,您可以使用 MIDI 系统的 api 来查找连接的 MIDI 设备,请参阅 the java tutorials了解更多信息。

关于java - 如何知道连接到系统的输入设备是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14293956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com