题外话:
本来吧,这么个小东西实在是没必要写一篇指南,但官方文档实在是写的烂...啥都没有,尤其在鼠标这...只好自行摸索...
安装
重要的话说三遍:
不要通过pip官方源直接安装!
不要通过pip官方源直接安装!
不要通过pip官方源直接安装!
安装使用如下命令源码编译安装:
pip install git+https://github.com/sibson/vncdotool.git
使用Demo
from vncdotool import api
from .config_handler import config
from enum import Enum
import time
button_left = 1
button_mid = 2
button_right = 3
global client
def connect():
global client
#注意下面配置改成自己的
client = api.connect('{}::{}'
.format(config.vnc.connect.ip, config.vnc.connect.port),
password=str(config.vnc.connect.password))
def get_screenshot(path=None):
client.refreshScreen()
if path is None:
path = config.default.states.path + "screen"
client.captureScreen(path + ".png")
def click(click_x, click_y):
client.mouseMove(click_x, click_y)
client.mousePress(button_left)
def double_click(click_x, click_y):
client.mouseMove(click_x, click_y)
client.mousePress(button_left)
time.sleep(0.1)
client.mousePress(button_left)
def right_click(click_x, click_y):
client.mouseMove(click_x, click_y)
client.mousePress(button_right)
def input(text):
for k in text:
client.keyPress(k)
client.keyPress('enter')
def scroll():
client.keyPress('pgdn')
# 用下一页来代替滚动
其他注意事项
- 如果想使用截图功能,需要另开一个vnc工具连接到pc保持开启才行
- 如果需要其他按键,请参考:https://github.com/sibson/vncdotool/blob/main/vncdotool/client.py前101行
网友评论