Events Xlib鼠标事件和按钮提示

Events Xlib鼠标事件和按钮提示,events,mouse,pointers,xlib,Events,Mouse,Pointers,Xlib,我已经写了一个简单的程序,它将报告一个特定窗口的按键和释放事件。在我的例子中,它主要是终端,因为我从终端调用程序。我能够在终端窗口中获取按键按下和释放事件(我在终端上使用了XSelectInput()和KeyPressMask和KeyReleaseMask),但ButtonPress和ButtonRelease不起作用。不只是这些,任何与鼠标相关的事件都不会被报告。知道为什么会这样吗 #include #include #include #include #include #include i

我已经写了一个简单的程序,它将报告一个特定窗口的按键和释放事件。在我的例子中,它主要是终端,因为我从终端调用程序。我能够在终端窗口中获取按键按下和释放事件(我在终端上使用了XSelectInput()和KeyPressMask和KeyReleaseMask),但ButtonPress和ButtonRelease不起作用。不只是这些,任何与鼠标相关的事件都不会被报告。知道为什么会这样吗

#include
#include
#include
#include
#include
#include

int main() {
Display *display = XOpenDisplay(NULL);
KeySym k;
int revert_to;
Window window;
XEvent event;

XGetInputFocus(display, &window, &revert_to);
XSelectInput(display, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);

while(1)
{
XNextEvent(display,&event);
  switch (event.type) {

  case KeyPress : printf("Key Pressed\n"); break;
  case KeyRelease : printf("Key Released\n"); break;
  case ButtonPress : printf("Button Pressed\n"); break;
  case ButtonRelease : printf("Button Released\n"); break;
  case EnterNotify : printf("Enter\n"); break;
  }
}
XCloseDisplay(display);
return 0;
}

您遇到的问题是Xlib只向一个客户端发送按钮按下/释放事件。我认为您正在使用的窗口已经有一个客户端正在侦听其鼠标事件。因此,您的SelectInput调用实际上没有设置按钮按下/释放掩码,并生成了一个您没有检查的错误。

还忘了提到,如果我使用xlib创建自己的窗口,将报告鼠标事件。那么,这是否意味着XSelectInput不能与我未映射的窗口一起使用?我可以问一下您试图构建什么的最终目的吗?