Linux守护进程改变用户输入流?
我想编写一个程序来重新映射用户输入,例如更改键盘布局之类的内容,以及更复杂的内容,例如制作速记程序(即“t qk fx jmps ovr t lzy dg”输出为“快速狐狸跳过懒狗”)。我更愿意在 X 级别或以下级别执行此操作。
我可以根据实际用户输出制作某种虚拟键盘吗?理想情况下,我想要某种简单的界面(即程序的标准输入是一系列真实的用户输入事件,输出是虚拟键盘的用户输入事件),但如果不可能,我仍然感兴趣指示如何做到这一点。我现在对 Linux 硬件设备、低级 X 东西或内核一无所知;事实上我对 Linux 还很陌生。 “基础”教程的链接不会被忽视。
I'd like to write a program to remap user input for stuff like changing keyboard layouts, but also more complex things like making a shorthand program (i.e. "t qk fx jmps ovr t lzy dg" outputs as "the quick fox jumps over the lazy dog"). I'd prefer to do this at the X level or below.
Can I make some kind of virtual keyboard based on actual user output? Ideally I'd like some kind of simple interface (i.e. standard input to the program is a series of real user input events, output is the user input events for the virtual keyboard), but if that's not possible I'd still be interested in pointers to how this can be done. I don't know anything about Linux hardware devices, low-level X stuff, or the kernel right now; in fact I'm fairly new to Linux. Links to "Basics" tutorials would not be unappreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Linux 事件子系统来执行此操作:
使用 Linux 输入事件接口 (evdev) 从任何输入设备接收事件。另请参阅
input.h
头文件了解有关实际 API 的更多信息。使用
EVIOCGRAB
ioctl 抓取键盘设备,这样除了您的守护进程之外,其他用户空间应用程序都不会收到任何输入事件。使用uinput界面创建新的虚拟键盘具有您需要的任何功能。另请参阅
uinput.h
头文件,了解有关uinput
API 和 此 以获得可读的演练。有一些应用程序可以作为示例,例如 EvRouter、ESE 密钥守护进程 和我自己的 evmapd。
You can use the Linux event subsystem to do this:
Use the Linux input event interface (evdev) to receive events from any input device. See also the
input.h
header file for more information on the actual API.Use the
EVIOCGRAB
ioctl to grab the keyboard device, so that no other userspace applications but your daemon will receive any input events.Use the uinput interface to create a new virtual keyboard with any features that you need. See also the
uinput.h
header file for more information on theuinput
API and this for a readable walkthrough.There are a few applications that could serve as an example, such as EvRouter, ESE Key Daemon and my own evmapd.