桌面自动化框架。用文本文件驱动键盘和鼠标。

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,y
  • coord "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,y
  • scroll 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

Grammer Definition

录制

你可以录制鼠标和键盘 播放列表文件:

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 ...

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java获取JEditorPane中字符的绝对位置   java Datetime:将时间段拆分为天、小时和分钟   java是使此HashMap更高效的一种方法   java项目reactor:collectList()之后的block()对Flux不起作用。创建()   java在Mac OSX上安装OpenCV   java递归地确定一组数字是否包含两个总和相等的子集   Quad2D曲线上的几何图形Java绘图箭头   java将SSL证书导入Glassfish 4。十、   java Android未找到处理Intent MediaScanner的活动   EclipseJava。安全cert.CertificateParsingException:java。木卫一。IOException:主题密钥,无法创建EC公钥   java我能在O(M log N)时间内完成吗?   java跟踪eclipse中的资源更改也在中。元数据和。项目   java如何完全禁用Android键盘   java返回到上一个活动