在 Ubuntu 中模拟鼠标移动 [英] Simulate mouse movement in Ubuntu

查看:24
本文介绍了在 Ubuntu 中模拟鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

我希望使用外部脚本从命令行自动移动鼠标光标并模拟鼠标按钮单击.我不想:

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:

  • 录制鼠标移动和播放(例如,xnee、xmacro)
  • 立即将鼠标从一个位置移动到另一个位置(例如,xdotool、Python 的 warp_pointer)

理想的解决方案

我想做的是:

  1. 编辑一个简单的脚本文件(例如,mouse-script.txt).
  2. 添加坐标、移动速度、延迟和按钮点击的列表.例如:
  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

  • 运行脚本:xsim <mouse-script.txt.
  • 问题

    如何自动移动鼠标,使其以特定速度从当前位置过渡到屏幕上的另一个位置?例如:

    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
    

    --rate 50 不存在于 xdotool.

    推荐答案

    在较新版本的 Ubuntu (14.04+) 上,您可以使用 Autopilot,一个 Ubuntu 的 UI 测试工具.它用于创建和运行用户界面测试,但也可用于基本的 GUI 自动化任务.

    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.

    安装:

    $ sudo apt-get install python3-autopilot
    

    一个示例脚本 (Python3) 用于自动化 鼠标移动:

    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()
    

    您可以像运行任何其他 Python3 脚本一样运行它.注意鼠标指针的移动!

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

    这篇关于在 Ubuntu 中模拟鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆