我想创建" InputOnly“窗口,它应该是不可见的,并接受输入,但当运行下面的代码时,我的InputOnly窗口确实得到了任何事件。我想让我的注意力集中在其他窗口上,并且仍然可以得到输入。我怎样才能做到这一点?
#include <X11/Xlib.h>
#include <iostream>
int main(void) {
Display *dsp;
Window root;
Window windows[2];
XEvent ev;
int i = 0;
dsp = XOpenDisplay(NULL);
root = RootWindow(dsp, DefaultScreen(dsp));
windows[i] = XCreateSimpleWindow(
dsp,
root,
0, 0, 200, 200,
1,
BlackPixel(dsp, DefaultScreen(dsp)),
WhitePixel(dsp, DefaultScreen(dsp))
);
XSelectInput(dsp, windows[i], 0);
XMapWindow(dsp, windows[i]);
++i;
XSetWindowAttributes at;
at.event_mask = KeyPressMask;
windows[i] = XCreateWindow(
dsp,
root,
10,10,200,200,
0,
CopyFromParent,
InputOnly,
0,
0,
&at
);
XSelectInput(dsp, windows[i], KeyPressMask);
//XMapWindow(dsp, windows[i]);
while(1) {
XNextEvent(dsp, &ev);
std::cout << "foo" << std::endl;
}
return 0;
}发布于 2012-02-01 16:05:40
尝试使用XWindowEvent()而不是XNextEvent()。这可能会解决您的问题,因为您有多个窗口。
https://stackoverflow.com/questions/9077757
复制相似问题