自动化操作脚本

文章目录

  • vbs
  • [openCV + pyautogui](#openCV + pyautogui)

vbs

SSH连接并执行指令操作

shell 复制代码
Dim WshShell 
Set WshShell=WScript.CreateObject("WScript.Shell") 

WshShell.Run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "ssh xcmg@10.27.40.103"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000
WshShell.SendKeys "123"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "cd agv_1 && xmake run"
WshShell.SendKeys "{ENTER}"

MQTT服务器启动

shell 复制代码
Dim WshShell 
Set WshShell=WScript.CreateObject("WScript.Shell") 

WshShell.Run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "C:\Users\USER\emqx-5.3.0-windows-amd64\bin\emqx start"
WshShell.SendKeys "{ENTER}"
shell 复制代码
Dim WshShell 
Set WshShell=WScript.CreateObject("WScript.Shell") 

WshShell.Run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "D:"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "cd D:\Program Files {(}x86{)}\work\emqx\bin"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "emqx start"
WshShell.SendKeys "{ENTER}"

openCV + pyautogui

python 复制代码
import cv2
import numpy as np
import pyautogui
import time

# 捕获屏幕的函数
def capture_screen():
    image = pyautogui.screenshot()
    image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
    return image

# 寻找目标图像的函数
def find_target(screen, target, threshold=0.8):
    result = cv2.matchTemplate(screen, target, cv2.TM_CCOEFF_NORMED)
    _, max_val, _, max_loc = cv2.minMaxLoc(result)
    if max_val > threshold:
        return max_loc
    return None

# 点击目标的函数
def click_target(target_image_path, waiting_time=5):
    # 等待程序加载或窗口出现
    time.sleep(waiting_time)

    target_image = cv2.imread(target_image_path)
    screen = capture_screen()
    target_location = find_target(screen, target_image)

    if target_location:
        # 计算图标的中心位置并点击
        target_center = (target_location[0] + target_image.shape[1]//2, target_location[1] + target_image.shape[0]//2)
        pyautogui.click(target_center)
        return True
    return False

# 主函数
def main():
    # 点击与软件链接的文件
    if not click_target('path_to_file_icon.jpg'):
        print("Failed to find the file icon.")
        return

    # 等待软件启动并点击软件界面中的按钮
    if not click_target('path_to_software_button.jpg', waiting_time=10):
        print("Failed to find the button in the software.")
        return

    # 点击新窗口中的按钮
    if not click_target('path_to_new_window_button.jpg', waiting_time=5):
        print("Failed to find the button in the new window.")
        return

    print("Operation completed successfully.")

if __name__ == "__main__":
    main()
相关推荐
嵌入式郑工1 小时前
LINUX驱动开发: 设备和驱动是怎么匹配的?
linux·运维·服务器
Turnsole_y2 小时前
pycharm自动化测试初始化
python·selenium
郭式云源生法则2 小时前
归档及压缩、重定向与管道操作和综合使用,find精确查找、find处理查找结果、vim高级使用、vimdiff多文件使用
linux·运维·服务器
getExpectObject()2 小时前
【jenkins】构建安卓
运维·jenkins
小池先生3 小时前
服务请求出现偶发超时问题,经查服务本身没问题,问题出现在nginx转发。
运维·服务器·nginx
weixin-a153003083163 小时前
[数据抓取-1]beautifulsoup
开发语言·python·beautifulsoup
AI量化投资实验室3 小时前
15年122倍,年化43.58%,回撤才20%,Optuna机器学习多目标调参backtrader,附python代码
人工智能·python·机器学习
java_logo3 小时前
vllm-openai Docker 部署手册
运维·人工智能·docker·ai·容器
倔强青铜三3 小时前
苦练Python第67天:光速读取任意行,linecache模块解锁文件处理新姿势
人工智能·python·面试
MANONGMN3 小时前
Linux 通配符与正则表达式(含实战案例+避坑指南)
linux·运维·正则表达式