钩键& Qt 4.6键盘组合 [英] Hook key & key combinations from keyboard with Qt 4.6

查看:177
本文介绍了钩键& Qt 4.6键盘组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个无窗口的应用程序,它只有任务栏上的一个图标(Windows,Mac OS X和Linux)。我想要它捕获一些关键&关键组合,让我们说Right Control + Right Shift。键入正确的组合,它会做一些事情,说截图。我可以在任务栏上进行无窗口的应用程序,图标和屏幕截图,但是我不知道如何在键盘上全局监视键盘组合。请叮嘱任何帮助或提示是非常感谢!感谢提前!

解决方案

系统范围的关键抓取是一个棘手的问题,但系统范围的关键钩子甚至更棘手。每个操作系统/ GUI都有自己的解决方案,至少用于抓取。 Qt4不公开此类功能,但 Qt eXTension库解决了其 QxtGlobalShortcut 。这是一个很好的包装:





所以你可以获取明确的键组合,即特定的键和修饰符(XGrabKey()允许一点),没有其他应用程序将得到。键盘序列,即连续按键组合,在此不受支持。






键盘钩功能更强大,因为它允许偷看在输入事件(或甚至过滤它们)。它不仅被键盘记录器使用,而且在这里也是典型的关联。



如果你进入Windows,那么你可以阅读:





在X11中,复杂得多。至少有两页可能要阅读:





有一个 X事件拦截扩展程序,但没有维护,最终已被删除。



希望可以在没有X11基础架构的帮助下完成。在Linux 2.6内核中有事件接口,称为 evdev ,可以在这里被利用。详细信息可以在 logkeys Linux keylogger 的源代码中找到。它也可以用类似于evdev的东西来完成。参见我的PoC项目:
kaos - 主要活动屏幕显示。



我没有Mac,所以没有进一步的参考。 ;)


Let's say I have a window-less application which has only an icon on the Taskbar (Windows, Mac OS X & Linux). I want it to capture some key & key combinations, let's say Right Control + Right Shift. Upon keying in correct, combination, it will do something, say take screenshot. I can do window-less app, icon on the Taskbar and screen capture but I don't know how to monitor keyboard globally for key combinations. Please kindly advise. Any help or hint is greatly appreciated! Thanks in advance!

解决方案

System-wide key grabbing is a tricky subject, but system-wide key hooking is even trickier. Every OS/GUI has its own solution, at least for grabbing. Qt4 doesn't expose such feature, but Qt eXTension library solves the problem with its QxtGlobalShortcut. It's a nice wrapper for:

So you can grab explicit key combination, i.e. particular key and modifiers (XGrabKey() allows a bit more), that no other application will get. Key sequences, i.e. consecutive key combinations, are not supported here.


Keyboard hooking is much more powerful, because it allows peeking at the input events (or even filtering them). It's not only used by keyboard loggers, but they are a typical association here.

If you're into Windows, then you can read:

In X11 it's much more complicated. There are at least a two pages you may want to read:

There was a X Event Interception Extension, but it wasn't maintained and eventually has been removed.

Hopefully it can be done without the help of X11 infrastructure. In Linux 2.6 kernel there is "Event interface", known as evdev, that can be exploited here. Details can be found in the source code of the logkeys Linux keylogger. It can also be done with something in effect similar to evdev. See my PoC project: kaos - Key Activity On-Screen display.

And I don't have Mac, so no further references. ;)

这篇关于钩键& Qt 4.6键盘组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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