How to get mouse click position

mousex11

I know I can get the position of the mouse pointer by executing xdotool getmouselocation. What I need is program that will run and let me know the position where the mouse pointer clicks.

Best Answer

You can use GNU Xnee to track your mouse events and then grep only mouse key press events. But since mouse click event doesn't contains mouse position you should store it from previous event or execute external command (e.g. xdotool) to get current mouse position.

Example:

$ cnee --record --mouse | awk  '/7,4,0,0,1/ { system("xdotool getmouselocation") }'

It will grab all left clicks. Change last number in awk command to get other keys (1 - left mouse, 2 - middle mouse, 3 - right mouse) or remove it to grab all of them.

Also event name probably may look different on your system. Just run $ cnee --record --mouse to find out it and replace that part in awk command.