2
我試圖在Windows 7下爲鍵盤(HID,如果有要求)編寫自定義「驅動程序」。最終目標是將兩個鍵盤連接到計算機,但將其中一個鍵的所有鍵映射到特殊(自定義)功能。libusb-win32 - 無法從鍵盤讀取
我的想法是使用libusb-win32作爲第二個鍵盤的驅動程序,並編寫一個小程序從鍵盤讀取數據並對其執行操作。我已經成功安裝了驅動程序,並且可以從我的程序中識別設備,但是即使按鍵,所有傳輸都會超時。
這裏是我的代碼:
struct usb_bus *busses;
struct usb_device *dev;
char buf[1024];
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
dev = busses->devices;
cout << dev->descriptor.idVendor << '\n' << dev->descriptor.idProduct << '\n';
usb_dev_handle *h = usb_open(dev);
cout << usb_set_configuration(h, 1) << '\n';
cout << usb_claim_interface(h, 0) << '\n';
cout << usb_interrupt_read(h, 129, buf, 1024, 5000) << '\n';
cout << usb_strerror();
cout << usb_release_interface(h, 0) << '\n';
cout << usb_close(h) << '\n';
並返回(在那些5秒我按很多鍵)
1133
49941
0
0
-116
libusb0-dll:err [_usb_reap_async] timeout error
0
0
這裏只有一個總線,一個設備,一個配置,一個接口和一個端點。 端點有bmAttributes = 3
這意味着我應該使用中斷傳輸(對吧?)
那麼爲什麼我沒有得到任何東西?我濫用libusb?你知道沒有libusb的方法嗎?
你說「...目標有兩個鍵盤......將其中一個鍵的所有鍵映射到特殊(自定義)功能。」你有沒有完成這個項目?它在某處可用嗎?我已經有了一段時間的完全相同的想法,從來沒有去攻擊它。謝謝!! – 2014-08-07 22:17:32
@JonasHeidelberg檢查了這個[gist](https://gist.github.com/xorserer/481356fa586fcaa426f5)。該項目本身就是C#,並且其中一些類缺失,但我認爲它可用於這種形式。 (整個項目不公開,我無法發佈) – nirbruner 2014-08-09 07:27:42