5

I'm looking for a solution that would display the current mouse cursor coordinates in realtime (i.e. NOT xdotool and NOT xev).

I need to move the mouse to a certain position, then press Alt-Tab to flip to another window and record the coordinates there. (This would not move the mouse, so the coordinate display would stay the same).

There's a Windows program that works BEAUTIFULLY for this purpose - http://download.cnet.com/Cursor-Position/3000-2383_4-75449858.html?tag=mncol;1

...but it doesn't even start up in Wine.

Alternately, instead of displaying the coordinates, if this solution could copy the coordinates (in XXX,YYY format) to the clipboard, upon pressing a hotkey, that would be even better.

Any suggestions would be much appreciated!

P.S. I'm running Ubuntu 12.04 LTS.

  • 1
    I don't know a program that do this specifically in Ubuntu. I would try luck into Unix & Linux instead (if you do that, please delete this question, since they don't like crossposting). – Braiam Sep 18 '13 at 2:56
3

Spartan solution: you can show the coordinates in real-time with xdotool if you create a bash script. Just execute this in a new Terminal:

while true; do xdotool getmouselocation; sleep 0.2; clear; done

Change the value after sleep to make it more or less "real-time". This requires bash, the default user shell in Ubuntu.

Better solution: if you have admin rights, install watch (sudo apt-get install watch), and then execute this in a new Terminal:

watch -ptn 0 "xdotool getmouselocation"

It uses xdotool but does not require bash.


Thank you b_laoshi for your suggestion!

  • 1
    You can do this without a while loop if desired... watch -n 0.1 xdotool getmouselocation – b_laoshi Jun 5 '17 at 6:03
  • Thank you! :-) You can obtain a faster and precise result with: watch -p -t -n 0 xdotool getmouselocation. This has the advantage of being locale-agnostic and removes the unnecessary information. – Lorenzo Ancora Jun 6 '17 at 16:47
0

Get coordinates and copy to clipboard

Displaying the coordinates in real-time has already been addressed, so I won't repeat that answer here. By creating a script and configuring a keyboard shortcut to run it, we can copy mouse coordinates to the clipboard in x,y format. Here's how:

  1. Install xdotool for grabbing coordinates and xsel for managing the clipboard.

    sudo apt-get install xdotool xsel
    
  2. Create a new script file with the following contents. Save the script and make it executable.

    #!/bin/bash
    xdotool getmouselocation | grep -oP "[0-9]+ y:[0-9]+" | sed 's/ y:/,/' | tr -d '\n' | xsel --clipboard
    
  3. Create a custom keyboard shortcut that calls your script for the desired key combination.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.