Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 807
svenstaro Avatar asked Dec 25 '11 11:12

svenstaro


2 Answers

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

like image 120
michaeljt Avatar answered Nov 10 '22 19:11

michaeljt


I know kcolorchooser does that and is written in C

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

like image 25
TryTryAgain Avatar answered Nov 10 '22 20:11

TryTryAgain