2013-01-12 33 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以獲取更多信息。

相關問題