windows - libusb-win32 - 无法从键盘读取

标签 windows libusb

我正在尝试在 Windows 7 下为键盘(HID,如果重要的话)编写一个自定义“驱动程序”。最终目标是将两个键盘连接到计算机,但映射其中一个键盘的所有键他们到特殊(自定义)功能。

我的想法是使用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';

它返回:

  1133
  49941
  0
  0
  -116
  libusb0-dll:err [_usb_reap_async] timeout error
  0
  0

(我在这 5 秒内按了很多键)

只有一种总线、一种设备、一种配置、一种接口(interface)和一种端点。 端点有 bmAttributes = 3 这意味着我应该使用中断传输(对吗?)

那为什么我什么也没得到呢?我是否滥用libusb?你知道没有 libusb 的方法吗?

最佳答案

实际上非常简单 - 从 USB 设备读取时,您必须准确读取正确的字节数。您可以通过阅读 wMaxPacketSize 来了解该金额。

显然,任何其他大小的读取请求都会导致超时。

关于windows - libusb-win32 - 无法从键盘读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719603/

相关文章:

windows - 仅重新映射 Windows 键,保留 Windows 键组合

c - libusb 程序的 makefile

macos - 如何在Mac OSX中重命名libusb动态库文件以强制其为静态链接?

linux - 以非 root 用户身份访问带有 libusb-1.0 的 USB 设备

rust - 如何改变 Iterator::find 的闭包中的项目?

python - 将 libusb 代码移植到 Python : interrupt transfer

windows - Go exec.Cmd() 导致 Python 脚本不导入模块?

windows - 注册表碎片整理程序

c++ - double 商?

windows - 如何使用 Windows cmdline 在一个长的衬里中设置一个变量?