From a41ae5252dbc1bbfdb3519bb30c9ce9be2df6bc2 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: Thu, 11 Apr 2024 23:29:16 +0800 Subject: [PATCH] issues/645 --- .../LunaTranslator/gui/settingpage_quick.py | 1 + .../LunaTranslator/gui/translatorUI.py | 19 ++++++++++--------- .../files/defaultconfig/config.json | 5 +++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_quick.py b/LunaTranslator/LunaTranslator/gui/settingpage_quick.py index d862619e..c6854ad2 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_quick.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_quick.py @@ -46,6 +46,7 @@ def setTab_quick_direct(self): windows.RegisterWindowMessage("Magpie_Core_CLI_Message_ToggleOverlay"), ), "_26": gobject.baseobject.translation_ui.ocr_once_signal.emit, + "_27": gobject.baseobject.translation_ui.simulate_key_enter, } for name in globalconfig["quick_setting"]["all"]: if name not in self.bindfunctions: diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 795c3c61..68b05155 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -390,15 +390,16 @@ class QUnFrameWindow(resizableframeless): rangeselct_function(self, ocroncefunction, False, False) - def addbuttons(self): - def simulate_key_enter(): - windows.SetForegroundWindow(gobject.baseobject.textsource.hwnd) - time.sleep(0.1) - while windows.GetForegroundWindow() == gobject.baseobject.textsource.hwnd: - time.sleep(0.001) - windows.keybd_event(13, 0, 0, 0) - windows.keybd_event(13, 0, windows.KEYEVENTF_KEYUP, 0) + @threader + def simulate_key_enter(self): + windows.SetForegroundWindow(gobject.baseobject.textsource.hwnd) + time.sleep(0.1) + while windows.GetForegroundWindow() == gobject.baseobject.textsource.hwnd: + time.sleep(0.001) + windows.keybd_event(13, 0, 0, 0) + windows.keybd_event(13, 0, windows.KEYEVENTF_KEYUP, 0) + def addbuttons(self): def simulate_key_ctrl(): windows.SetForegroundWindow(gobject.baseobject.textsource.hwnd) time.sleep(0.1) @@ -469,7 +470,7 @@ class QUnFrameWindow(resizableframeless): ), ( "simulate_key_enter", - lambda: threading.Thread(target=simulate_key_enter).start(), + self.simulate_key_enter, ), ( "copy_once", diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index d13a9272..4cd3e483 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -571,6 +571,11 @@ "use": false, "name": "进行一次OCR", "keystring": "" + }, + "_27": { + "use": false, + "name": "模拟按键Enter", + "keystring": "" } } },