Simulate mouse movement in Ubuntu

房东的猫 提交于 2019-12-02 23:44:47
  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

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!