简体   繁体   中英

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. 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.

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

I know kcolorchooser does that and is written in C

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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