如何在X11中全局捕获每次鼠标点击?

发布于 2024-12-22 22:57:07 字数 347 浏览 1 评论 0原文

我想捕获 X11 中的每个鼠标单击事件并将它们传递给我的 C++ 应用程序。我不仅想捕获在我的主窗口顶部进行的点击,而且还想捕获每一次与我的主窗口无关的点击。看起来我可以使用 XGrabPointer 轻松完成此任务。然而,我希望一切都表现得好像我从未抓住过这个事件。也就是说,我希望事件能够继续正常的旅程,到达层次结构中的其他客户端,我只想成为第一个窥探事件的人。我不希望这些事件被“吃掉”。

当谷歌搜索这个问题时,似乎有几个解决方案出现,但显然所有这些解决方案都已损坏或已弃用。最有前途的是 Xrecord + Xtest,但这似乎也已被弃用。

现在看来这应该使用 Xinput2 来完成,但有关如何使用它的信息确实很少。我希望能得到一些见解。

I want to capture every mouse click event in X11 and pass them to my C++ application. I don't only want to capture the clicks made on top of my main window but each and every one with no regard to my main window. It looks like I could easily accomplish this using XGrabPointer. However, I want everything to behave as though I never grabbed the event. That is, I want the events to continue on their normal journey to other clients down the hierarchy, I merely want to be the first one to snoop in on events. I don't want the events to be "eaten".

There seem to be a couple of solutions to this that come up when Googling the issue but apparently all of them are broken or deprecated. The most promising one was Xrecord + Xtest but that seems deprecated as well.

It looks like this should be done using Xinput2 nowadays but information on how to use it is really scarce. I'd appreciate some insight.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘然心甜 2024-12-29 22:57:07

虽然已经很晚了,但仍然 - 您可能想看看“xkey”应用程序[1],它监听所有打开窗口的所有按键事件。如果您这样做,您还想观察新窗口的创建。

[1] http://www.stllinux.org/meeting_notes/1997/0619/ xkey.html

Somewhat late in the day, but still - you might want to take a look at the "xkey" application[1], which snoops on all key events to all open windows. If you went that way you would also want to watch for new window creation.

[1] http://www.stllinux.org/meeting_notes/1997/0619/xkey.html

莫多说 2024-12-29 22:57:07

我知道 kcolorchooser 是用 C 语言编写的,

也许值得参考:
http://www.kde.org/applications/graphics/kcolorchooser/development

I know kcolorchooser does that and is written in C

Maybe it is worth the reference:
http://www.kde.org/applications/graphics/kcolorchooser/development

好菇凉咱不稀罕他 2024-12-29 22:57:07

也许您应该看一下 xev 代码:它捕获每个可以想象到的 X 事件。

Maybe you should have a look at the xev code: it captures each and every X event imaginable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文