2013-01-12 37 views
2

iam只是简单地试图了解连接到系统的输入设备和输出设备。有没有任何API来获取有关使用Java的输入/输出设备的信息?如何知道连接到系统的输入设备

EDIT

独立于任何操作系统。

请建议。

+0

您正在尝试使用哪种操作系统? – sadaf2605

+0

更新问题 – developer

+0

@Marko输入设备likw键盘,麦克风和鼠标等
输出设备如显示设备 – developer

回答

2

要查找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. 
     } 
    } 
} 

同样,你可以使用API​​的MIDI系统找到MIDI设备连接的东西,看到the java tutorials以获取更多信息。

相关问题