自动化操作脚本

文章目录

  • 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()
相关推荐
都叫我大帅哥5 分钟前
当AI遇上话痨:LangGraph的`trim_messages`裁剪艺术完全指南
python·langchain·ai编程
石小千16 分钟前
Nginx服务做负载均衡网关
运维·nginx·负载均衡
都叫我大帅哥18 分钟前
RNN:当神经网络有了记忆,却得了健忘症
python·深度学习
Neng_Miao40 分钟前
权限管理命令
linux·运维·服务器
shandianchengzi41 分钟前
【笔记】ROS1|5 ARP攻击Turtlebot3汉堡Burger并解析移动报文【旧文转载】
linux·运维·网络安全·机器人·arp·turtlebot
禁默1 小时前
进程生命周期管理:从创建到终止的完整逻辑
linux·运维·服务器
mit6.8241 小时前
[自动化Adapt] 父子事件| 冗余过滤 | SQLite | SQLAlchemy | 会话工厂 | Alembic
python·算法·自动化
2025年一定要上岸1 小时前
【Django】-7- 实现注册功能
后端·python·django
不念霉运3 小时前
Gitee:本土化DevOps平台如何助力中国企业实现高效研发协作
运维·gitee·devops
爱喝水的鱼丶3 小时前
SAP-ABAP:ABAP Open SQL 深度解析:核心特性、性能优化与实践指南
运维·开发语言·数据库·sql·性能优化·sap·abap