简体   繁体   English

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

[英]How to globally capture every mouse click in X11?

I want to capture every mouse click event in X11 and pass them to my C++ application.我想捕获 X11 中的每个鼠标单击事件并将它们传递给我的 C++ 应用程序。 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.看起来我可以使用 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.最有前途的一个是 Xrecord + Xtest,但它似乎也被弃用了。

It looks like this should be done using Xinput2 nowadays but information on how to use it is really scarce.现在看起来这应该使用 Xinput2 来完成,但是关于如何使用它的信息真的很少。 I'd appreciate some insight.我很感激一些见解。

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.有点晚了,但仍然 - 您可能想看看“xkey”应用程序[1],它监听所有打开的窗口的所有关键事件。 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 [1] http://www.stllinux.org/meeting_notes/1997/0619/xkey.html

I know kcolorchooser does that and is written in C我知道 kcolorchooser 这样做并且是用 C 编写的

Maybe it is worth the reference: http://www.kde.org/applications/graphics/kcolorchooser/development也许值得参考: http : //www.kde.org/applications/graphics/kcolorchooser/development

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM