现在,我想在X11中捕获全局鼠标单击事件
我试着安装一个x11event过滤器,但是它不能在全球范围内工作。
class XApplication: public QApplication
{
public:
XApplication (int & argc, char **argv):
QApplication (argc , argv)
{
}
protected:
bool x11EventFilter (XEvent *e)
{
qDebug() << "X11 Event: " << e->type;
return QApplication::x11EventFilter(e);
}
};更新
我的意思是在窗口外,当我点击窗口时,上面的代码是有效的。
发布于 2012-04-12 14:53:58
您可以使用X11类从Qt查询QX11Info信息。见它的文件。然后您可以从它中使用原始的Xlib。
您可以使用XGrabPointer()。如果您使用它,其他应用程序将不会接收指针事件,而指针被抓取。man XGrabPointer会帮你的。
订阅事件的“正常”方式是在窗口上使用XSelectInput(),但问题是必须在每个现有窗口上调用XSelectInput。看它的手册..。
我知道xxf86dga扩展有一些与鼠标相关的调用,但我不知道它们是做什么的。
XQueryPointer()是查询指针状态而不从其他窗口窃取事件的另一种方法。
我能想到的唯一其他地方是XInput扩展,但我也不确定它是否会对您有所帮助。
有关处理X11事件的良好参考资料,请参阅X11源代码:http://cgit.freedesktop.org/xorg/app/xev
使用XGrabPointer的示例代码:
#include <stdio.h>
#include <assert.h>
#include <X11/Xlib.h>
int main(void)
{
Display *d;
Window root;
d = XOpenDisplay(NULL);
assert(d);
root = DefaultRootWindow(d);
XGrabPointer(d, root, False, ButtonPressMask | ButtonReleaseMask |
PointerMotionMask, GrabModeAsync, GrabModeAsync, None,
None, CurrentTime);
XEvent ev;
while (1) {
XNextEvent(d, &ev);
switch (ev.type) {
case ButtonPress:
printf("Button press event!\n");
break;
case ButtonRelease:
printf("Button release event!\n");
break;
case MotionNotify:
printf("Motion notify event!\n");
break;
default:
printf("Unknown event...\n");
}
}
XCloseDisplay(d);
return 0;
}使用:gcc x11mouse.c -o x11mouse -lX11编译
https://stackoverflow.com/questions/10081588
复制相似问题