最後更新: 2019-06-25
HomePage
https://github.com/sibson/vncdotool/
目錄
- Install
- Basic Usage
- Capture Screen
Install
# 在 virtualenv 安裝 vncdotool
pip install virtualenv
virtualenv venv-vncdotool
source venv-vncdotool/bin/activate
# setup venv by requirements-X.txt
requirements-2.6.txt
# requirements known to work with python2.6 Pillow==2.6.1 Twisted==14.0.2 wsgiref==0.1.2 zope.interface==4.1.1
pip install -r requirements-2.6.txt
pip install vncdotool
Test & Check Version
vncdo --version
vncdo 0.12.1
Basic Usage
Connect VNC Server
-s SERVER # Format ADDRESS[:DISPLAY|::PORT]
-p PASSWORD
i.e.
# Default port: 5900
vncdo -s 192.168.88.150 capture screen.png
# Cust port: 5921
vncdo -s 192.168.88.150:21 key enter
# Cust port: 15921
vncdo -s 192.168.88.150::15921 type "hello world"
一 cmd 多 action
move 500 100 click 1 type "ping 192.168.88.1" key enter
特別 key
enter, esc, shift-a, ctrl-c, ctrl-alt-del, super-r
Capture Screen
# capture full screen
vncdo -s $server::$port capture tmp.png
# capture a region of the screen
vncdo -s $server::$port rcapture FILE X Y W H
Example
compare_full_screen.sh
function compare_full_screen(){ while true do vncdo -s $server::$port capture tmp.png r=`compare -metric PSNR $1 tmp.png /dev/null 2>&1` i=${r%.*} echo $i if (( $i > 20 )); then echo "SAME" break fi sleep 5 done } compare_full_screen myscreen.png
move & click
* You should almost always issue a click with move
正確:
vncdo move 100 100 click 1
錯誤
vncdo move 100 100 vncdo click 1
delay 與 pause
--delay=MILLISECONDS # delay MILLISECONDS between action [Default: 10ms]
i.e.
vncdo --delay=2000 -s $server::$port type c type m type d
pause SECONDS #wait SECONDS before sending next command
vncdo -s $server::$port key super-r pause 2
vncdo -s $server::$port key delete
Macro
i.e. Disable firewall rule
#!/bin/bash ## vnc host setings Server="192.168.88.150" Port="5921" VNCDO=/root/MyScripts/vnc_bot/venv-vncdotool/bin/vncdo VNCDO_CON="$VNCDO -s $Server::$Port" function DisFwGrp() { local fwGrpNm="$1" # start cmd.exe $VNCDO_CON key super-r type cmd key enter # cli to disable fw rule group $VNCDO_CON type "netsh advfirewall firewall set rule group=" \ key shift-\" type "$fwGrpNm" key shift-\" \ type " new enable=no" key enter # exit cmd.exe $VNCDO_CON type "exit" key enter } #DisFwGrp "Remote Desktop"
* "double quotes" 要用 key shift-\" 發送