前言
在日常办公中总有些每天必完成的动作,比如:登陆即时聊天、登陆OA门户、每日系统巡检、报表下载通报等,一些工作简单但必做的事。最近在UOS系统下找到个合适的解决方案:xdotool。它类似windows下的按键精灵,通过模拟鼠标键盘的操作实现自动化。对我而言重要一点是:UOS系统默认安装xdotool,经过几天了解分享下xdotool基本使用技巧。
正文
- 模拟键盘输入、快捷键
xdotool type "hello world!"
xdotool type "hello \n world!" #多行文本
xdotool key a
xdotool key ctrl+alt+t #模拟快捷键
xdotool key Return #回车
- 模拟鼠标操作:移动鼠标、点击、拖动等
xdotool click 1 #左键单击
xdotool click 2 #鼠标中键
xdotool click 3 #右键单击
xdotool click 4 #滚轮向上
xdotool click 5 #滚轮向下
xdotool click --repeat 2 1 #左键双击
xdotool mousedown 1 mousemove 600 600 mouseup 1 #左键拖动
xdotool getmouselocation #当前鼠标位置
xdotool mousemove 100 100 click 1 #移动到指定位置单击
xdotool mousemove_relative 10 10 #鼠标相对位置移动
- 窗口管理:查找窗口、激活窗口、移动、调整大小等
xdotool search --name "Firefox" windowactivate #查找窗口并激活第一个窗口
xdotool getactivewindow windowsmove 100 100 #移动最前端窗口到(100,100)
xdotool getactivewindow windowsize 800 600 #设置最前端窗口大小800x600
- xdotool脚步文件
#!/usr/bin/xdotool
search —class=“Goole Chrome” windowactivate
gateactivewindow windowsize 100% 100%
key ctrl+t
key ctrl+l
type “https://vitshare.cn”
key Return
运行脚本:./scriptfile
- uos配置自动快捷方式启动
设置->键盘和语言->快捷键,添加自定义快捷键。
总结
总之,xdotool
是一个功能强大且灵活的工具,适合在 X11 环境下进行各种自动化操作,释放你的双手。
参考
xdotool开源代码
发现一个xdotool,是个神器
linux 下的按键精灵 xdotool
shell脚本:在Linux中模拟击键和鼠标移动, 键盘精灵, xdotool 模拟用户交互