18

Problem

Am looking to automatically move the mouse cursor and simulate mouse button clicks from the command-line using an external script. Am not looking to:

  • Record mouse movement and playback (e.g., xnee, xmacro)
  • Instantly move the mouse from one location to another (e.g., xdotool, Python's warp_pointer)

Ideal Solution

What I'd like to do is the following:

  1. Edit a simple script file (e.g., mouse-script.txt).
  2. Add a list of coordinates, movement speeds, delays, and button clicks. For example:
    (x, y, rate) = (500, 500, 50)
    sleep = 5
    click = left
    
  3. Run the script: xsim < mouse-script.txt.

Question

How do you automate mouse movement so that it transitions from its current location to another spot on the screen, at a specific velocity? For example:

xdotool mousemove 500 500 --rate 50

The --rate 50 doesn't exist with xdotool.

2 Answers 2

20

on newer versions of Ubuntu (14.04+), you can use Autopilot, a UI testing tool for Ubuntu. It is made for creating and running user interface tests, but can also be used for basic GUI automation tasks.

to install:

$ sudo apt-get install python3-autopilot

an example script (Python3) to automate mouse movement:

#!/usr/bin/env python3

from autopilot.input import Mouse

mouse = Mouse.create()
mouse.move(100, 50)
mouse.click()

You would run this just like any other Python3 script. Watch your mouse pointer move!

Sign up to request clarification or add additional context in comments.

3 Comments

Even after installing python3-autopilot, I'm getting ImportError: No module named autopilot.input. Turns out I had to run using python3. Cheers
ubuntu python3 msg is Python 3.8.5 (default, Jul 28 2020, 12:59:40) but i have the same error ImportError: No module named autopilot.input what could i do?
Dont use pip3 install, but sudo apt install, then no more ImportError
13
  1. Download xaut for Python
  2. Follow the README instructions
  3. Run:
    sudo apt-get install swig x11proto-xext-dev libx11-dev libxtst-dev
    cd /usr/local/src
    tar zxf xaut-0.2.0.tar.gz
    ./configure
    
  4. Edit src/Makefile
  5. Change the CFLAGS line as follows:
    CFLAGS = -Wall -fPIC -fno-stack-protector
  6. Run:
    make
    
  7. Copy /usr/local/src/xaut-0.2.0/python/build/lib/* to a new directory.
  8. Change to that new directory.
  9. Copy and paste the following script into mm.py:
    import xaut
    mouse = xaut.mouse()
    delay mouse.move_delay( 100 )
    mouse.move( 500, 500 )
    
  10. Run the script:
    python mm.py

1 Comment

Also, when you do the steps abobe it will fail on Ubuntu 11.10. First of all in my case in the makefile I had to add the absolute path of libX11.so which is not in /usr/local/lib as the makefile suggests but in usr/local/lib/i386-linux-gnu. Then when u fix that it can compile again. So change ld -shared to gcc -shared in the makefile and that's it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.