zoukankan      html  css  js  c++  java
  • xdotool xdotool模拟击键和鼠标移动--CutyCapt是一个截图工具,xvfb-run

    最近在做一个生成网站缩略图的功能,从网上查到相关资料,现与大家分享,xvfb这个软件,安装上之后一条命令就能执行此操作。很容易的就生成了自己想要的缩略图。

    xvfb-run -运行在一个虚拟的X服务器环境中的指定的X客户端或命令。

    xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=http://www.google.com --out=example.png

     Run COMMAND (usually an X client) in a virtual X server environment.

    https://www.phpsong.com/2542.html

    CutyCapt是一个截图工具
    官方网站 http://cutycapt.sourceforge.net/

    sudo apt search cutycapt

    sudo apt-get install cutycapt

    启动的软件窗口太小,设置:

    1
    xdotool search --name ".*Mozilla Firefox" windowsize 1440 900

    http://www.cnblogs.com/CraryPrimitiveMan/p/4944982.html

    下面来介绍以下xdotool

    我用的是ubuntu,安装只需要只想如下命令:

    sudo apt-get install xdotool

    虽然xdotool是那样的直观,但它仍然是个脚本程序。因此,为了要正确地使用它,你还是得了解它的语法。不过敬请放心,相对于程序的功能而言,语法还是比较简单易学的。

    首先,模拟击键是很容易的。你可以从终端敲入下面的命令:

    xdotool key [name of the key]

    如果你想要连接两个键,可以在它们之间使用 “+” 操作符。它看起来像这样:

    xdotool key alt+Tab

    这两个组合键可以为你切换窗口。

    要想让 xdotool 帮你输入,可以使用以下命令:

    xdotool type ''

    这些对于基本的击键而言已经足够了。但是,xdotool 的众多长处之一,就是它可以获取特定窗口的焦点。它可以获取右边的窗口,然后在里面输入,所有你记录下的按键都不会人间蒸发,而是老老实实的如你所愿的出现在那里。要获得该功能,一个简单的命令可以搞定:

    xdotool search --name [name of the window] key [keys to press]

    该命令将在打开的窗口中搜索对应名称的窗口,并聚焦于该窗口,然后模拟击键。

    来点更高级的,但很有用哦,xdotool 可以模拟鼠标移动和点击,看这命令:

    xdotool mousemove x y

    你可以将光标定位到屏幕坐标(x,y)(像素)。你也可以使用 “click” 参数来组合:

    xdotool mousemove x y click 1

    这会让鼠标移动到(x,y),然后点击鼠标左键。“1”代表鼠标左键,“2”则是滚轮,“3”则是右键。

    最后,一旦你这些命令根植于你脑海,你也许想要实际转储于文件来编辑并试着玩玩。鉴于此,就会有超过一个语句以上的内容了。你需要的就是写一个bash脚本了:

    #!/bin/bash
    xdotool [command 1]
    xdotool [command 2]
    etc

    或者你可以使用:

    xdotool [filename]

    这里你将命令写入到一个独立的文件中,然后通过将文件名作为 xdotool 命令的参数。

    项目地址:http://www.semicomplete.com/projects/xdotool/

    文档地址:http://www.semicomplete.com/projects/xdotool/xdotool.xhtml

    关于之前小游戏模拟点击左右箭头的代码如下:

    for i in {1..1000}
    do
       xdotool key Left
       xdotool key Right
    done
  • 相关阅读:
    Ubuntu adb devices :???????????? no permissions (verify udev rules) 解决方法
    ubuntu 关闭显示器的命令
    ubuntu android studio kvm
    ubuntu 14.04版本更改文件夹背景色为草绿色
    ubuntu 创建桌面快捷方式
    Ubuntu 如何更改用户密码
    ubuntu 14.04 返回到经典桌面方法
    ubuntu 信使(iptux) 创建桌面快捷方式
    Eclipse failed to get the required ADT version number from the sdk
    Eclipse '<>' operator is not allowed for source level below 1.7
  • 原文地址:https://www.cnblogs.com/SZLLQ2000/p/7054196.html
Copyright © 2011-2022 走看看