35

I'd like to be able to display the current location of the pointer on the X display. Is there any application which does this?

3
  • 1
    I found a solution. There's a package called xdotool that has an application named getmouselocation. It works like this: sconklin@xps-1:~$ xdotool getmouselocation x:1285 y:10 screen:0
    – sconklin
    Jul 19, 2011 at 21:33
  • 4
    please write that in an actual answer, once the site allows you to.
    – Isaiah
    Jul 19, 2011 at 22:24
  • I wrote it up as an answer for you (wiki mode to not take undue rep for it). Jul 20, 2011 at 7:52

5 Answers 5

41

There's a package called xdotool that has an application named getmouselocation, available from ubuntu repositories with sudo apt-get install xdotool. Running the command

xdotool getmouselocation

will output

x:1285 y:10 screen:0
1
  • 17
    Probably "watch xdotool getmouselocation" is what most people are looking for. Dec 31, 2013 at 12:44
14
  1. Install xdotool
  2. Open a terminal and paste this:

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

Move the cursor over the screen and you will see live coordinates update on terminal.

1
  • 4
    or watch -n 0.1 "xdotool getmouselocation"
    – Ziyuan
    May 3, 2019 at 9:58
3

xev from the command line shows this. Try the following.

xev

Current coordinates are displayed as root:(<x>,<y>).

4
  • 6
    It seems to be xev only shows the location when the mouse cursor is pointing at the window which xev opens. Jul 20, 2011 at 7:54
  • Check out updated answer.
    – kcpr
    Sep 11, 2015 at 7:36
  • 2
    @kcpr, what? I don't see any root:(<x>,<y>) in the terminal window that holds the xev data. Jan 3, 2016 at 0:04
  • @user1717828, did You try what Ilari Kajaste suggested?
    – kcpr
    Jan 3, 2016 at 0:08
3

Here's a python script:

#!/usr/bin/env python3
from Xlib import display
import sys

while True:
    c = display.Display().screen().root.query_pointer()._data
    x = c["root_x"]
    y = c["root_y"]

    sys.stdout.write(f'{x:04} {y:04}\r')
    sys.stdout.flush()

Save it to file myscript.py, and launch with python3 myscript.py.

0

Not a native Linux solution, but if you have Wine installed, Pixie is a free (as in beer) small app that will show you both your cursor's coordinates and the color of the pixel directly underneath it in several formats.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .