您如何获得隐藏设备的所有权? [英] How can you take ownership of a hid device?

查看:84
本文介绍了您如何获得隐藏设备的所有权?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拥有一个可能已经插入的hid设备的所有权,使用它的输出,同时防止其他人(X11或终端)使用它.

如果能帮助我,我不想假装自己是终端机,而是想垄断一个特定的隐藏或字符设备.这个想法是,某些隐藏的设备可能会被x/terminal识别为鼠标/键盘,但是第二个鼠标或键盘可以用于其他功能,但是要做到这一点,您需要确保它们没有将虚假输入发送到鼠标/键盘.打开终端.

有人对如何做到有任何见识吗?

解决方案

我已完成此操作-我的特定应用程序是一个守护程序,可从USB HID条形码读取器(以USB HID键盘设备形式)读取事件. >

为此,我使用了事件设备接口,打开了与我所使用的设备相对应的/dev/input/event*设备.然后,您可以在设备上发布EVIOCGRAB ioctl,该ioctl可以将其捕获以专用,并在设备可用时读取事件(代表按键,鼠标移动等).

(当设备被抢占专用时,只有您的应用程序才能看到其中的事件).

What I would like to take ownership of a hid device that may already have been plugged in, consume it's output, while preventing others(X11 or terminal) from consuming it.

If I can help it, I don't want to pretend to be a terminal, but rather to monopolize a particular hid or character device. The idea is that some hid devices may be recognized as mice/keyboards by x/terminal, but a second mouse or keyboard could be used for something else, but to do that you need to make sure they aren't sending spurious input into an open terminal.

Does anyone have any insight as to how this might be done?

解决方案

I have done this - my specific application was a daemon that read events from a USB HID barcode reader (which presents as a USB HID keyboard device).

To do this I used the event device interface, opening the /dev/input/event* device corresponding to the device I was after. You can then issue the EVIOCGRAB ioctl on the device, which grabs it for exclusive use, and read events (which represent keypresses, mouse movements etc) from the device as they become available.

(When the device is grabbed for exclusive use, only your application will see events from it).

这篇关于您如何获得隐藏设备的所有权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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