gpt4 book ai didi

c++ - 创建 InputOnly 窗口

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:33:26 24 4
gpt4 key购买 nike

我想创建“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;
}

最佳答案

尝试使用 XWindowEvent() 而不是 XNextEvent()。这可能会解决您的问题,因为您有多个窗口。

关于c++ - 创建 InputOnly 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9077757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com