钩键& Qt 4.6键盘组合 [英] Hook key & key combinations from keyboard with Qt 4.6
问题描述
系统范围的关键抓取是一个棘手的问题,但系统范围的关键钩子甚至更棘手。每个操作系统/ GUI都有自己的解决方案,至少用于抓取。 Qt4不公开此类功能,但 Qt eXTension库解决了其 QxtGlobalShortcut 。这是一个很好的包装:
- XGrabKey() / X11中的XUngrabKey(),
- RegisterHotKey() / 在Windows中的UnregisterHotKey(),
- Mac OS X中的RegisterEventHotKey()/ UnregisterEventHotKey()。
所以你可以获取明确的键组合,即特定的键和修饰符(XGrabKey()允许一点),没有其他应用程序将得到。键盘序列,即连续按键组合,在此不受支持。
键盘钩功能更强大,因为它允许偷看在输入事件(或甚至过滤它们)。它不仅被键盘记录器使用,而且在这里也是典型的关联。
如果你进入Windows,那么你可以阅读:
在X11中,复杂得多。至少有两页可能要阅读:
- X.Org Wiki - 开发/文档/ InputEventProcessing - 有一些背景
- 利用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:
- XGrabKey()/XUngrabKey() in X11,
- RegisterHotKey()/UnregisterHotKey() in Windows,
- RegisterEventHotKey()/UnregisterEventHotKey() in Mac OS X.
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:
- Hooks and DLLs by Joseph M. Newcomer,
- Hooks.
In X11 it's much more complicated. There are at least a two pages you may want to read:
- X.Org Wiki - Development/Documentation/InputEventProcessing - to have some background,
- Exploiting X11 to monitor keystrokes - to understand difficulties.
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屋!