自动化操作脚本

文章目录

  • 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 [email protected]"
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()
相关推荐
pp-周子晗(努力赶上课程进度版)6 分钟前
【Linux】线程ID、线程管理、与线程互斥
linux·运维·服务器·开发语言
啊哈哈哈哈哈啊哈哈29 分钟前
R4打卡——tensorflow实现火灾预测
人工智能·python·tensorflow
闻道☞33 分钟前
RAGFlowwindows本地pycharm运行
python·pycharm·ragflow
默凉1 小时前
注意力机制(np计算示例)单头和多头
python
咸其自取1 小时前
Flask(3): 在Linux系统上部署项目
python·ubuntu
未来之窗软件服务1 小时前
数字人,磁盘不够No space left on device,修改python 执行环境-云GPU算力—未来之窗超算中心
linux·开发语言·python·数字人
暴富奥利奥2 小时前
基于 OpenCV 的图像与视频处理
opencv·学习
时迁2472 小时前
基于Docker+k8s集群的web应用部署与监控
运维·docker·kubernetes
python_chai2 小时前
Python多进程并发编程:深入理解Lock与Semaphore的实战应用与避坑指南
开发语言·python·高并发·多进程··信号量
Cheng_08292 小时前
llamafactory的包安装
python·深度学习