自动化操作脚本

文章目录

  • 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()
相关推荐
草莓熊Lotso2 小时前
GCC/G++ 编译器完全指南:从编译流程到进阶用法(附实操案例)
linux·运维·服务器·网络·c++·人工智能·自动化
workflower7 小时前
时序数据获取事件
开发语言·人工智能·python·深度学习·机器学习·结对编程
鸠摩智首席音效师7 小时前
linux 系统中 Shutting Down, Restarting, Halting 有什么区别 ?
linux·运维·服务器
CIb0la7 小时前
Linux 将继续不支持 HDMI 2.1 实现
linux·运维·服务器
C++业余爱好者8 小时前
Java 提供了8种基本数据类型及封装类型介绍
java·开发语言·python
吕了了8 小时前
85 微PE吕了了修改版--更新!
运维·windows·电脑·系统
鹿鸣天涯8 小时前
Kali Linux 2025.4 发布:桌面环境增强,新增 3 款安全工具
linux·运维·安全
AI Echoes9 小时前
构建一个LangChain RAG应用
数据库·python·langchain·prompt·agent
学习&笔记9 小时前
MTK(系统篇)user版本无法使用setenforce 0命令关闭selinux权限
linux·运维·服务器
派大鑫wink9 小时前
从零到精通:Python 系统学习指南(附实战与资源)
开发语言·python