【问题标题】:Interacting with raw HID devices using Python?使用 Python 与原始 HID 设备交互?
【发布时间】:2020-04-10 03:27:39
【问题描述】:

我正在尝试编写一些 Python 代码以通过其原始隐藏接口与设备(键盘)进行通信。键盘向主机呈现多个 HID 设备(键盘、系统键、鼠标、原始隐藏等),我只能通过查看“使用页面”和“使用”属性来识别正确的设备。

我查看了 Python hid 模块(在 Fedora 31 中封装在 python3-hidapi-0.7.99.post20-13.fc31.x86_64 中),但在 hid.enumerate() 的返回值中,usage_pageusage 的值在所有情况下都是 0

>>> import hid
>>> import pprint
>>> pprint.pprint([(x['path'], x['usage_page']) for x in hid.enumerate() if x['vendor_id'] == 1240 and x['product_id'] == 61138])
[(b'0002:0010:00', 0),
 (b'0002:0010:02', 0),
 (b'0002:0010:03', 0),
 (b'0002:0010:01', 0),
 (b'0002:0010:04', 0),
 (b'0002:0010:05', 0)]

有什么方法可以从 Python 中获取usage_page 信息?看起来这已通过/sys/class/hidraw/hidraw<N>/device/report_descriptor 暴露在 sysfs 中可用的设备报告描述符中,但如果可能的话,我想通过编写自己的枚举代码来避免重新发明轮子。

【问题讨论】:

    标签: python usb hid


    【解决方案1】:

    在后台,您的 python 应用程序使用 hidapi C 库,目前不支持在 Linux 上获取 usage/usage_page-es。

    所以,回答你的直接问题:目前没有办法直接从 Python 获取 usage/usage_page,特别是使用 hid 库。

    有一个积极的讨论来添加这种现成的支持: https://github.com/libusb/hidapi/pull/139

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 1970-01-01
      • 2011-09-22
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      相关资源
      最近更新 更多