Linux 是否可以使计算机充当蓝牙 HID 设备?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4177186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to make a computer behave as a bluetooth HID device?
提问by Michael Wehner
Is it possible to make a computer behave as a bluetooth HID device? That is, given a local machine with a standard USB keyboard plugged into it, other devices could discover this machine and use it as a bluetooth keyboard.
是否可以使计算机充当蓝牙 HID 设备?也就是说,给定一台插入了标准 USB 键盘的本地机器,其他设备可以发现这台机器并将其用作蓝牙键盘。
I'd like to create a linux or OS X application (or use an existing one, though I've found none) which can behave as described above, but I'm not sure where to start, or if it's even possible.
我想创建一个 linux 或 OS X 应用程序(或使用现有的应用程序,尽管我没有找到),它的行为可以如上所述,但我不确定从哪里开始,或者是否有可能。
So:
所以:
- Is what I'm describing possible?
- Are there any existing applications that do what I describe?
- If no application already exists (I'm assuming not), are there bluetooth libraries or bindings that will help? (I'm pretty comfortable using most of today's popular languages, so I'd prefer a library most directly suited to the task, so long as it's available in linux or OS X.)
- Failing any of the above, the bluetooth spec looks pretty dense. Are there specific guides or other starting points applicable to the problem at hand that I can read?
- 我所描述的可能吗?
- 是否有任何现有的应用程序可以执行我所描述的操作?
- 如果没有应用程序已经存在(我假设不存在),是否有蓝牙库或绑定会有所帮助?(我很习惯使用当今大多数流行的语言,所以我更喜欢最直接适合该任务的库,只要它在 linux 或 OS X 中可用。)
- 如果上述任何一项失败,蓝牙规范看起来非常密集。是否有适用于我可以阅读的手头问题的特定指南或其他起点?
I realize that such an application would most likely need to steal the normal keyboard input, possibly providing some KVM-like hotkey for switching between providing input to the host operating system and sending the input over bluetooth to the connected device, but I'm considering that problem to be outside the scope of this question.
我意识到这样的应用程序很可能需要窃取正常的键盘输入,可能会提供一些类似 KVM 的热键,用于在向主机操作系统提供输入和通过蓝牙将输入发送到连接的设备之间进行切换,但我正在考虑这个问题超出了这个问题的范围。
回答by thkala
It is definitely possible on Linux. Some time ago I found this project:
在 Linux 上绝对是可能的。前段时间我发现了这个项目:
http://nohands.sourceforge.net/index.html
http://nohands.sourceforge.net/index.html
They emulate a full-blown headset with audio and keyboard controls on the Linux bluetooth stack. If they can emulate something like that, you would probably be able to emulate something simpler like a keyboard.
他们在 Linux 蓝牙堆栈上模拟带有音频和键盘控件的成熟耳机。如果他们可以模拟类似的东西,你可能就能模拟更简单的东西,比如键盘。
回答by Christian Uhl
I don't know if this is helpful, nor if it is still alive and working, but perhaps you could try this link.
我不知道这是否有帮助,也不知道它是否还活着和工作,但也许你可以试试这个链接。
Another one that might or might not be helpful in some way is remuco, but I don't know if they are using a Bluetooth HID profile.
另一个在某些方面可能有帮助也可能没有帮助的方法是remuco,但我不知道他们是否使用蓝牙 HID 配置文件。
回答by Abid Ullah
It is possible, however I don't think I'll be able explain it very well and I don't know the entire answer. A BT HID device works as a server and waits for connections to come to it. In linux, using the bluez stack, first you would have to advertise the HID service for other devices to see. I think you do that using the sdp.h and sdp-lib.h header files(the second header maybe called something else, I'm on a windows computer and can't check). So you would have to add the HID service record to you computer for other devices to see it. You would have to create a program that first adds this service to the record, then waits for other devices to connect, then handle the pairing process, Bluez might handle this for you, or you might have to do some things to it, I'm not quite sure. You should also read the Bluetooth HID Spec found at the http://www.bluetooth.com/English/Technology/Building/Pages/Specification.aspxsite. This document contains the details of the SDP record relevant to HID. Also the book Bluetooth essentials for programmersis pretty good to introduce you into bluetooth programming
这是可能的,但是我认为我无法很好地解释它,而且我不知道完整的答案。BT HID 设备用作服务器并等待连接到来。在 linux 中,使用 bluez 堆栈,首先您必须为其他设备宣传 HID 服务才能看到。我认为你使用 sdp.h 和 sdp-lib.h 头文件(第二个头文件可能被称为别的东西,我在 Windows 计算机上无法检查)。因此,您必须将 HID 服务记录添加到您的计算机以供其他设备查看。您必须创建一个程序,该程序首先将此服务添加到记录中,然后等待其他设备连接,然后处理配对过程,Bluez 可能会为您处理,或者您可能需要对其做一些事情,我我不太确定。http://www.bluetooth.com/English/Technology/Building/Pages/Specification.aspx站点。本文档包含与 HID 相关的 SDP 记录的详细信息。程序员的蓝牙必备这本书也很好地向您介绍了蓝牙编程
I would like to have given a more concise answer, with more detail, but that's all I know ATM. I am also trying do something similar, but spare time is so hard to find ;) I'm also not on my Linux box and can't check all the details. If your are still interested, let me know and i'll try to expand my answer.
我想给出一个更简洁的答案,更详细,但这就是我所知道的 ATM。我也在尝试做一些类似的事情,但很难找到空闲时间;) 我也不在我的 Linux 机器上,无法检查所有细节。如果您仍然感兴趣,请告诉我,我会尝试扩展我的答案。
回答by Lubomir Rintel
It is indeed entirely possible with Linux and Bluez. See: https://github.com/lkundrak/virtkbd/blob/master/btkbdd.pod
Linux和Bluez确实完全有可能。参见:https: //github.com/lkundrak/virtkbd/blob/master/btkbdd.pod