Linux或Ubuntu下模拟鼠标跟按键等输入事件

Linux或Ubuntu下模拟鼠标和按键等输入事件
Linux或Ubuntu下模拟鼠标和按键等输入事件

在Linux或Ubuntu下,我们可以用xdotool这个工具来模拟鼠标和按键等输入事件。相应的,在Windows操作系统中,有一款名为“按键精灵”的工具也可以提供这些功能。由于我的主要工作是在ubuntu上完成的(windows xp跑在我的虚拟机中),所以在这里我就介绍下xdotool的常见用法。

linux或ubuntu下xdotool常见用法:
  • ubuntu上安装xdotool: $ sudo apt-get install xdotool
  • 模拟回车:$ xdotool key KP_Enter
  • 模拟按下左侧shift键(不弹起):$ xdotool keydown Shift_L
  • 模拟弹起shift:$ xdotool keyup Shift_L
  • 模拟按下A并弹起:$ xdotool key a
  • 模拟ctrl+a:$ xdotool key Ctrl+a
  • 模拟按下向上方向键:$ xdotool key Up
  • 获取鼠标位置:$ xdotool getmouselocation
  • 模拟鼠标移动:$ xdotool mousemove X坐标值 Y坐标值
  • 模拟鼠标左键点击1次:$ xdotool click 1
  • 模拟鼠标中键(滚轮键)点击1次:$ xdotool click 2
  • 模拟鼠标右键点击1次:$ xdotool click 3
  • 模拟选择并复制文本:模拟鼠标点击起始位置 -> 模拟鼠标移动到末端位置 -> 模拟按下左shift键(不弹起) -> 模拟鼠标左键点击 -> 模拟弹起左shift -> 模拟Ctrl+c

  • xdotool的更多用法:
  • $ xdotool help

  • 以上

    想要更好的阅读体验,欢迎到我的个人博客查看原文


    Linux或Ubuntu下模拟鼠标跟按键等输入事件