首页 > 解决方案 > 如何在 X11/Xlib 的根窗口中读取 KeyPress 和 ButtonPress 事件?

问题描述

我正在编写一个绘制到根窗口的 C 程序。(这部分有效)

我现在需要在根窗口上接受键盘和鼠标输入(在根窗口上单击和按键)。我试过这个:

XSelectInput(display, rootWindow, KeyPressMask);
XNextEvent(display, &event)

但是 KeyPress 永远不会出现。我也尝试过使用ButtonPressMask,但这会产生错误:

X Error of failed request:  BadAccess

是否可以在不必挂钩所有输入的情况下做到这一点?我在堆栈溢出中看到了这个想法:Detect modifier key release in X11 root window but it hooks into all input as far as I cantell.

我正在使用 i3wm,所以我没有任何东西作为我的默认根窗口。(如果这有帮助)

标签: cx11xlibxserver

解决方案


推荐阅读