在 Ubuntu 中监控键盘按键 [英] Monitoring Keyboard keys in Ubuntu

查看:24
本文介绍了在 Ubuntu 中监控键盘按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在 Ubuntu 的后台进程中获取数据

我正在编写一个程序来监控键盘上的按键.但是我的程序可能在前台或后台运行.我听说有特定于操作系统的系统调用,即使运行系统调用的程序在后台,程序员也可以监控键盘活动.我是 Ubuntu 编程新手,所以请有人告诉我那个操作系统系统调用是什么.

I am writting a program which monitors the keys pressed on a keyboard. But my program may be running in foreground or in background. I heard that there is OS specific system call which lets the programmer to monitor keyboard activity even when the program running the system call is in background. I am new to Ubuntu programming so please somebody tell me what is that OS system call.

注意:该程序仅用于教育目的.这是学校项目的一部分..

Note: This program is strictly for educational purposes. It is a part of School project..

问候

推荐答案

大多数 Ubuntu 系统(至少是 Ubuntu 新手用户的桌面)都运行 X11 窗口服务器(如 Xorg).该服务器(仅)正在获取原始键盘和鼠标设备输入.它处理它们以将 X11 协议事件 传递给客户端应用程序(例如您的 firefox 浏览器或您的emacs 编辑器,或者你的 gnome 或 xterm 终端).

Most Ubuntu systems (at least desktop for novice Ubuntu users) are running an X11 window server (like Xorg). That server (only) is getting the raw keyboard and mouse device inputs. It processes them to deliver X11 protocol events to client applications (like e.g. your firefox browser, or your emacs editor, or your gnome or xterm terminal).

您可以花时间(几个月)了解所有这些(也许从 freedesktop 开始)您也可以切换到其他项目,也许只是使用 Gtk(在 Gnome 中)编写一个有趣的 GUI 应用程序或Qt(在 KDE 中).所有 Linux 图形工具包库都构建在与 X11 协议接口的库之上,通常是 XlibXCB.

You could spend your time (months) understanding all of them (perhaps starting from freedesktop) You could also switch to some other project, perhaps just coding an interesting GUI application using Gtk (within Gnome) or Qt (within KDE). All Linux graphical toolkits libraries are built above a library interfacing the X11 protocol, usually Xlib, or XCB.

如果您想开始学习 Linux 编程,请阅读 高级 Unix 编程高级 Linux 编程.之后,花很多时间了解tty-s的奥秘,并熟悉 syscalls(2).然后熟悉 Qt 或 GTK 等图形工具包.

If you want to start learning Linux programming, read Advanced Unix Programming and Advanced Linux Programming. After than, take a lot of time to understand the mysteries of tty-s, and become familiar with syscalls(2). Then become familiar with a graphical toolkit like Qt or GTK.

然后你就会开始明白要准确回答你问得不好和可疑的问题是多么困难.(答案很大程度上取决于观点 - Xorg 看到的关键事件不同于其他应用程序,尤其是 X 客户端,并且非常复杂).

And then you'll just begin to understand how hard it is to answer precisely your ill-asked and suspicious question. (the answer strongly depends upon the point of view - Xorg seeing different key events than other applications, notably X clients, and is very complex).

一旦您理解了我提供给您的链接中的所有概念,您就可以更准确地提出您的问题.当您以更精确和技术性的术语重新提出您的问题时(特别是解释您希望在哪个级别监控键盘和鼠标),显示您试验过的代码,我们将能够(并且愿意)回答你.

Once you've understood all the concepts in the links I gave you, you'll be able to ask more precisely your question. When you'll re-ask your question in more precise and technical terms (in particular explaining at which level you want to monitor the keyboard & mouse), showing the code that you experimented, we'll be able (and willing) to answer you.

这篇关于在 Ubuntu 中监控键盘按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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