尝试获取鼠标点击坐标时出错

Errors while trying to get mouse click coordinates

我正在尝试 运行 本主题的代码(第一个答案):getting mouseclick coordinates with Xlib 但它给了我一些错误。

输出:

$ ./a.out
X Error of failed request:  BadAccess (attempt to access private resource denied)
  Major opcode of failed request:  2 (X_ChangeWindowAttributes)
  Serial number of failed request:  8
  Current serial number in output stream:  8

应该使用:gcc c.cc -lX11
并将一个字符串更改为:XSelectInput(display, root, ButtonReleaseMask);