如何在Linux上捕获原始HID输入? [英] How can I capture raw HID input on Linux?

查看:68
本文介绍了如何在Linux上捕获原始HID输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想完成的工作的简短版本:我有一个脚踏板(INFINITY-IN-USB-1,如果您有兴趣的话)可以实现为通用HID设备,希望它在Linux上表现为 Ctrl Alt 键.我正在寻找X级别的东西,即不仅仅是单个程序.

Short version of what I want to accomplish: I have a foot pedal (INFINITY-IN-USB-1, if that's of any interest) that is implemented as a generic HID device, and I would like it to be behave as Ctrl and Alt keys on Linux. I'm looking for something on the level on X, i.e. not just individual programs.

较长版本:通过调用DLL函数 RegisterRawInputDevices GetRawInputData 并在隐藏状态下侦听输入,我可以在Windows XP中使用此设置窗户.所有操作都可以通过相当简单的 AutoHotkey 脚本完成(如果有人感兴趣,可以在此处发布).关键是,不需要任何额外的驱动程序等.只需本机Windows DLL文件.

Longer version: I have this setup working in Windows XP by calling DLL functions RegisterRawInputDevices and GetRawInputData and listening to the input in a hidden window. All is accomplished with a fairly straightforward AutoHotkey script (I can post here if anyone is interested). The point is, there isn't any need for any extra driver, etc.; only the native Windows DLL files are needed.

我希望此设置可在Linux上使用(更具体地说,是Ubuntu下的 GNOME ,但我偶尔使用其他发行版/窗口管理器,因此赞赏X级的解决方案).该脚踏板不会注册为键盘甚至操纵杆,而是注册为带有UsagePage 12,用法3的HID设备.

I want this setup to work on Linux (more specifically GNOME under Ubuntu, but I do occasionally use other distributions/window managers, so a solution on the level of X is appreciated). This foot pedal does not register itself as keyboard or even joystick, but as a HID device with UsagePage 12, Usage 3.

我注意到最新的Ubuntu可以检测并使用 Microsoft Natural Keyboard 上的收藏夹键>,它也注册为HID设备*.我在Windows上使用的按键与使用脚踏板的方法相同(即,没有附带的软件).因此,我假设这种踏板操作也可以在Linux上运行,但是问题是如何实现的?

I notice that the latest Ubuntu can detect and use the favorite keys on the Microsoft Natural Keyboard, which also register as HID device*. I make use of those keys on Windows using the same method as I use the foot pedal (i.e., without the bundled software). So I assume that this pedal thing can work on Linux as well, but the question is how?

(我是Linux上较低级别的知识的新手,因此请在适当的地方慷慨地提供指向简介或教程的链接.)

(I'm new to the lower-level stuff on Linux, so please be generous with links to introduction or tutorial whenever applicable.)

*对于那些不知道的人,Microsoft Natural Keyboard将其注册为常规键盘和通用HID设备.在某些应用程序(例如捆绑的应用程序)不知道如何解释HID输入的情况下,常规键将起作用,但是收藏夹键和特殊功能键无效.

为澄清起见,Linux不是 看到踏板踩踏输入.它可以识别USB设备,但是 xev 不会为踏板踩踏提供任何输出.我看到有人成功使用 Wine 下的踏板来制作转录软件的报道,但这必须以Windows方式工作并且不能提供我想要的东西(这使踏板在所有本机Linux应用程序中都像键盘一样).是否需要一些底层Linux键盘驱动程序?

To clarify, Linux is not seeing the pedal presses as input. It does recognize the USB device, but xev doesn't give any output for pedal presses. I have seen reports of people successfully using the pedal under Wine for transcription software, but that must work in a Windows way and does not give what I want (which is making the pedal look like a keyboard to all native Linux applications). Is some low-level Linux keyboard driver needed?

更多信息:如果我在终端机上发布

Here's some more information: If I issue this in the terminal

cat /dev/usb/hiddev0

( dev/usb/hiddev0 是我的踏板),我得到与踏板踩踏相对应的原始代码.那是一个开始.我知道这些原始代码的含义:二进制中的0001、0010、0100分别对应于每个踏板,踏板踩踏的组合发送这些二进制数的组合,并释放仍在踩下的任何踏板的踏板触发输入(如果有的话)踏板抬起,发送了0000.)

(dev/usb/hiddev0 is my pedal), I get raw codes corresponding to my pedal presses. That's a start. I know what those raw code means: in binary, 0001, 0010, 0100 corresponds to each pedal, respectively, and combination of pedal presses sends combination of those binary number, and releases of pedal trigger input of whatever pedal still being pressed (if all pedal is up, 0000 is sent).

如何让X收听 dev/usb/hiddev0 并将原始代码转换为特殊的键码,以便我可以使用xmodmap或其他方式映射它们?

How can I get X to listen to dev/usb/hiddev0 and translate the raw codes into maybe a special keycode so that I can map them with xmodmap or something?

推荐答案

您需要 uinput .您将侦听/dev/usb/hiddev0,然后创建要在/dev/input/uinput 上发送的新事件.

You'll want uinput. You'll listen on your /dev/usb/hiddev0 and then create new events that you'll send out on /dev/input/uinput.

对此进行了解释,并提供了一些教程:在Linux- 2.6.x中使用uinput驱动程序发送用户输入 {这是EInfochips的仪表板"出版物2007年1月发行,在

This explains it and gives a little tutorial: Using uinput driver in Linux- 2.6.x to send user input {This is the EInfochips' "Dashboard" publication issue January 2007 "Tip of the Month" article mentioned on this archived page}.

这篇关于如何在Linux上捕获原始HID输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆