|
@@ -1,5 +1,6 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
-from datetime import datetime
|
|
|
|
|
|
+from datetime import datetime
|
|
|
|
+import threading
|
|
import pyautogui
|
|
import pyautogui
|
|
from scriptBase.imgFind import pcacc_img
|
|
from scriptBase.imgFind import pcacc_img
|
|
from scriptBase.mouseClick import pcacc_mouse
|
|
from scriptBase.mouseClick import pcacc_mouse
|
|
@@ -52,6 +53,7 @@ def binarize_image(image):
|
|
|
|
|
|
|
|
|
|
def waitFindImg(imgPath, waitTime, preWaitTime, isCV=False):
|
|
def waitFindImg(imgPath, waitTime, preWaitTime, isCV=False):
|
|
|
|
+ pre = time.time()
|
|
if preWaitTime > 0:
|
|
if preWaitTime > 0:
|
|
myTimeSleep(preWaitTime)
|
|
myTimeSleep(preWaitTime)
|
|
#sleep 0.2s per times
|
|
#sleep 0.2s per times
|
|
@@ -61,17 +63,15 @@ def waitFindImg(imgPath, waitTime, preWaitTime, isCV=False):
|
|
if ret:
|
|
if ret:
|
|
return ret, pos_cur
|
|
return ret, pos_cur
|
|
else:
|
|
else:
|
|
- myTimeSleep(0.2)
|
|
|
|
- curTime = curTime + 0.2
|
|
|
|
- print("waitFindImg failed", imgPath)
|
|
|
|
|
|
+ myTimeSleep(0.1)
|
|
|
|
+ curTime = time.time() - pre
|
|
|
|
+ costTime = time.time() - pre
|
|
|
|
+ print(f"waitFindImg failed, cost:{costTime}, img:{imgPath}")
|
|
return False, None
|
|
return False, None
|
|
|
|
|
|
-def waitFindImg_withBool(imgPath, waitTime, preWaitTime, isCV=False):
|
|
|
|
- ret, pos = waitFindImg(imgPath, waitTime, preWaitTime, isCV)
|
|
|
|
- return ret
|
|
|
|
-
|
|
|
|
|
|
|
|
def waitClickImg_noWait(imgPath, waitTime, preWaitTime, isCV=False):
|
|
def waitClickImg_noWait(imgPath, waitTime, preWaitTime, isCV=False):
|
|
|
|
+ pre = time.time()
|
|
if preWaitTime > 0:
|
|
if preWaitTime > 0:
|
|
myTimeSleep(preWaitTime)
|
|
myTimeSleep(preWaitTime)
|
|
#sleep 0.2s per times
|
|
#sleep 0.2s per times
|
|
@@ -83,11 +83,16 @@ def waitClickImg_noWait(imgPath, waitTime, preWaitTime, isCV=False):
|
|
myTimeSleep(0.5)
|
|
myTimeSleep(0.5)
|
|
return True, pos_cur
|
|
return True, pos_cur
|
|
else:
|
|
else:
|
|
- myTimeSleep(0.2)
|
|
|
|
- curTime = curTime + 0.2
|
|
|
|
- print("waitClickImg_noWait failed", imgPath)
|
|
|
|
|
|
+ myTimeSleep(0.1)
|
|
|
|
+ curTime = time.time() - pre
|
|
|
|
+ costTime = time.time() - pre
|
|
|
|
+ print(f"waitClickImg_noWait failed, cost:{costTime}, img:{imgPath}")
|
|
return False, (-1, -1)
|
|
return False, (-1, -1)
|
|
|
|
|
|
|
|
+def waitFindImg_withBool(imgPath, waitTime, preWaitTime, isCV=False):
|
|
|
|
+ ret, pos = waitFindImg(imgPath, waitTime, preWaitTime, isCV)
|
|
|
|
+ return ret
|
|
|
|
+
|
|
def waitClickImg_noWait_withBool(imgPath, waitTime, preWaitTime, isCV=False):
|
|
def waitClickImg_noWait_withBool(imgPath, waitTime, preWaitTime, isCV=False):
|
|
ret, pos = waitClickImg_noWait(imgPath, waitTime, preWaitTime, isCV)
|
|
ret, pos = waitClickImg_noWait(imgPath, waitTime, preWaitTime, isCV)
|
|
return ret
|
|
return ret
|
|
@@ -295,13 +300,27 @@ def game_region():
|
|
tmpRet, tmpPos = find_window_pos('Mumu模拟器12',)
|
|
tmpRet, tmpPos = find_window_pos('Mumu模拟器12',)
|
|
return tmpRet, tmpPos
|
|
return tmpRet, tmpPos
|
|
|
|
|
|
-def save_game_screen(fileHeader = ""):
|
|
|
|
- regionRet, regionPos = game_region()
|
|
|
|
- screenshot = pyautogui.screenshot(region=regionPos)
|
|
|
|
- curData = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
|
|
|
|
- fileName = "temp_pictures/" + fileHeader + "_" + curData + ".png"
|
|
|
|
- screenshot.save(fileName)
|
|
|
|
- return True
|
|
|
|
|
|
+def save_game_screen(fileHeader=""):
|
|
|
|
+ try:
|
|
|
|
+ regionRet, regionPos = game_region()
|
|
|
|
+ screenshot = pyautogui.screenshot(region=regionPos)
|
|
|
|
+ curData = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
|
|
|
|
+ fileName = "temp_pictures/" + fileHeader + "_" + curData + ".png"
|
|
|
|
+ screenshot.save(fileName)
|
|
|
|
+ return True
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(f"截图保存失败: {e}")
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+# 创建并启动截图线程
|
|
|
|
+def start_screenshot_thread(fileHeader=""):
|
|
|
|
+ screenshot_thread = threading.Thread(
|
|
|
|
+ target=save_game_screen,
|
|
|
|
+ args=(fileHeader,),
|
|
|
|
+ name=f"ScreenshotThread_{fileHeader}"
|
|
|
|
+ )
|
|
|
|
+ screenshot_thread.start()
|
|
|
|
+ return screenshot_thread
|
|
|
|
|
|
def start_recording():
|
|
def start_recording():
|
|
global g_recorder
|
|
global g_recorder
|