|
|
@@ -1,7 +1,9 @@
|
|
|
+
|
|
|
# -*- coding: utf-8 -*-
|
|
|
from datetime import datetime
|
|
|
import threading
|
|
|
import pyautogui
|
|
|
+import win32com
|
|
|
from scriptBase.imgFind import pcacc_img
|
|
|
from scriptBase.mouseClick import pcacc_mouse
|
|
|
import time
|
|
|
@@ -13,6 +15,8 @@ from PIL import ImageFilter
|
|
|
import io
|
|
|
from scriptBase.ocr import *
|
|
|
from scriptBase.record import ScreenRecorder
|
|
|
+import win32gui
|
|
|
+import win32con
|
|
|
|
|
|
g_recorder = ScreenRecorder()
|
|
|
|
|
|
@@ -282,6 +286,51 @@ def ocrAuto(gamestr, positions):
|
|
|
lineStr = ""
|
|
|
return lineStr
|
|
|
|
|
|
+def tryMoveTopWindow(gameStr):
|
|
|
+ """尝试查找并置顶包含指定关键词的窗口"""
|
|
|
+ mumu_windows = []
|
|
|
+
|
|
|
+ def enum_callback(hwnd, param):
|
|
|
+ """枚举回调函数"""
|
|
|
+ if win32gui.IsWindowVisible(hwnd):
|
|
|
+ window_title = win32gui.GetWindowText(hwnd)
|
|
|
+ if gameStr in window_title:
|
|
|
+ param.append((hwnd, window_title))
|
|
|
+ return True
|
|
|
+
|
|
|
+ # 枚举所有顶级窗口
|
|
|
+ win32gui.EnumWindows(enum_callback, mumu_windows)
|
|
|
+
|
|
|
+ if not mumu_windows:
|
|
|
+ print(f"未找到包含 '{gameStr}' 的窗口")
|
|
|
+ return False
|
|
|
+
|
|
|
+ # 输出找到的窗口信息(调试用)
|
|
|
+ print(f"找到 {len(mumu_windows)} 个匹配窗口:")
|
|
|
+ for i, (hwnd, title) in enumerate(mumu_windows):
|
|
|
+ print(f" {i+1}. 句柄: {hwnd}, 标题: {title}")
|
|
|
+
|
|
|
+ # 处理第一个找到的窗口
|
|
|
+ target_hwnd, target_title = mumu_windows[0]
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 设置窗口置顶
|
|
|
+ win32gui.SetWindowPos(target_hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0,
|
|
|
+ win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
|
|
|
+
|
|
|
+ # 激活窗口到前台
|
|
|
+ try:
|
|
|
+ win32gui.SetForegroundWindow(target_hwnd)
|
|
|
+ except Exception as e:
|
|
|
+ print(f"设置前台窗口时警告: {e}")
|
|
|
+
|
|
|
+ print(f"窗口已置顶: {target_title}")
|
|
|
+ return True
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(f"设置窗口置顶时出错: {e}")
|
|
|
+ return False
|
|
|
+
|
|
|
def yys_ocrAuto(positions):
|
|
|
return ocrAuto('MuMu安卓设备', positions)
|
|
|
|
|
|
@@ -342,3 +391,6 @@ def click_waitimg(pos_x,pos_y,img):
|
|
|
pcacc_mouse.click(pos_x,pos_y)
|
|
|
retry_times-=1
|
|
|
return retry_times > 0
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ tryMoveTopWindow('MuMu安卓设备')
|