From 9341aac0b694578c789f1a3cfdcb282579948755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Wed, 21 Aug 2024 09:03:14 +0800 Subject: [PATCH] switch --- LunaTranslator/LunaTranslator/textsource/ocrtext.py | 13 ++++++++++--- docs/zh/ocrparam.md | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/LunaTranslator/LunaTranslator/textsource/ocrtext.py b/LunaTranslator/LunaTranslator/textsource/ocrtext.py index 61735421..be71237b 100644 --- a/LunaTranslator/LunaTranslator/textsource/ocrtext.py +++ b/LunaTranslator/LunaTranslator/textsource/ocrtext.py @@ -121,9 +121,16 @@ class ocrtext(basetext): triggered = True laststate = this if triggered and gobject.baseobject.hwnd: - p1 = windows.GetWindowThreadProcessId(gobject.baseobject.hwnd) - p2 = windows.GetWindowThreadProcessId(windows.GetForegroundWindow()) - triggered = p1 == p2 + for _ in range(2): + # 切换前台窗口 + p1 = windows.GetWindowThreadProcessId(gobject.baseobject.hwnd) + p2 = windows.GetWindowThreadProcessId( + windows.GetForegroundWindow() + ) + triggered = p1 == p2 + if triggered: + break + time.sleep(0.1) if triggered: time.sleep(globalconfig["ocr_trigger_delay"]) for _ in range(len(self.savelastimg)): diff --git a/docs/zh/ocrparam.md b/docs/zh/ocrparam.md index 4344d918..85951074 100644 --- a/docs/zh/ocrparam.md +++ b/docs/zh/ocrparam.md @@ -42,7 +42,7 @@ OCR的结果是不稳定的,经常对于图片的微小扰动会使文本发 ### 鼠标键盘触发+等待稳定 -以下鼠标键盘事件将触发该方法:按下鼠标左键、按下Enter、松开Ctrl、松开Shift、松开Alt +以下鼠标键盘事件将触发该方法:按下鼠标左键、按下Enter、松开Ctrl、松开Shift、松开Alt。如果绑定了游戏窗口,则仅当游戏窗口为前台窗口时,才会触发方法。 触发该方法后,由于需要等待游戏渲染新的文本,或文本可能不是立即出现(文本速度不是最快),因此需要稍微等待一小段时间,直到显示的文本稳定。