桌面自动化框架。用文本文件驱动键盘和鼠标。
self-driving-desktop的Python项目详细描述
自动驾驶桌面
桌面自动化框架。 用文本文件驱动键盘和鼠标。
pip install self-driving-desktop
sdd playlist.txt [--record]
播放列表
# Set screen size
screen "1080p";
# Create Coordinates
coords {
"center": {
"1080p": [960, 540],
"720p": [640, 360]
}
};
# Import playlist files
import "test/main.txt";
# Create a playlist
playlist "openChrome" {
# Run programs in the shell
shell "google-chrome";
sleep 2.0;
# Name the new window
active "hofChrome";
sleep 0.5;
# Use hotkeys to arrange
hotkeys "winleft" "right";
sleep 1;
};
playlist "closeChrome" {
# Focus a named window
focus "hofChrome";
hotkeys "alt" "f4";
sleep 1;
};
playlist "readTheDocs" {
# Go to a webpage
focus "hofChrome";
sleep 0.2;
# Type the URL
write "https://docs.hofstadter.io\n" 0.05;
# Goto an imported coordinate
coord "getting-started" 0.5;
};
# Move the mouse in a square
playlist "repeatTest" {
mm 100 100 1;
mm 1000 100 1;
mm 1000 500 1;
mm 100 500 1;
};
# Our main playlist
playlist "main" {
# Goto a named coordinate, also with offset
coord "center" 1;
coord "center" 250 -250 1;
# Operate the browser
play "openChrome";
play "readTheDocs";
play "closeChrome";
# Play a playlist multiple times
play "repeatTest" 4;
};
# Set the global delay between steps
delay 0.025;
# Finally, play our main playlist
play "main";
语法
顶层:
- 文件包含步骤和播放列表
- 步骤是唯一可以运行的
- play运行播放列表
# relative imports from file
import "relative/path.txt";
# named coordinates
coords {
# coord name
"center": {
# screen identifier
"1080p": [960, 540],
"720p": [640, 360]
}
};
# define playlists
playlist "my-playlist" {
steps...;
};
playlist "main" {
steps...;
# run playlists from playlists
play "my-playlist"
}
# set the screen identifier
screen "1080p";
# run a playlist
play "my-playlist" "main";
步骤:
play "name" "nameB" ... [N];
:运行一个或多个播放列表,可以选择重复n次。delay x.y;
:将步骤之间的延迟设置为x.y秒sleep x.y;
:睡眠x.y秒screen "screen";
:设置屏幕分辨率标识符shell "quoted strings"+;
:从程序中执行命令
窗口:
active "someName";
:命名活动窗口focus "someName";
:聚焦一个命名窗口
鼠标:
mouse x y s;
:在s秒内将鼠标移到x,ycoord "name" s;
:在s秒内将鼠标移到指定坐标coord "name" x y s;
:在s秒内移动到具有偏移量的命名坐标click;
:单击鼠标左键btnclick [left,middle,right];
btndown [left,middle,right];
btnup [left,middle,right];
drag [left,middle,right] x y s;
:在s秒内将鼠标拖动到x,yscroll n;
:滚动n行,负片向上hscroll n;
:水平滚动n“clicks”,负数为左
键盘:
keypress "key";
keydown "key";
keyup "key";
hotkeys "quoted" "keys" ...;
:同时按一些键write "quoted string\n";
:键入字符串,“\n”是回车
剪贴板:
copy;
,只要ctrl-c
paste;
,只要ctrl-v
save_clipboard "name";
将剪贴板内容保存到“name”load_clipboard "name";
从“name”加载剪贴板内容copy_clipboard "name";
复制并将剪贴板内容保存到“名称”paste_clipboard "name";
从“name”&;paste加载剪贴板内容
所有键都来自pyautogui
录制
你可以录制鼠标和键盘 播放列表文件:
sdd record.txt --record
注意,不是所有的键都工作。
一个用来修复某些问题的键映射是here。
开发设置
virtualenv --python python3 penv
source penv/bin/activate
pip install -r requirements.txt
export PYTHONPATH=.
python self_driving_desktop/__main__.py ...