Show *realtime* mouse cursor coordinates? (Cursor mod / overlay) Also, copy to clipboard?

15,191

Solution 1

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!

Solution 2

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.

Share:
15,191
user193844
Author by

user193844

Updated on September 18, 2022

Comments

  • user193844
    user193844 over 1 year

    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.

    • Braiam
      Braiam over 10 years
      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).
  • b_laoshi
    b_laoshi almost 7 years
    You can do this without a while loop if desired... watch -n 0.1 xdotool getmouselocation
  • Lorenzo Ancora
    Lorenzo Ancora almost 7 years
    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.