diff --git a/cpp/winsharedutils/SimpleBrowser.cpp b/cpp/winsharedutils/SimpleBrowser.cpp index 41ebb936..a3394c61 100644 --- a/cpp/winsharedutils/SimpleBrowser.cpp +++ b/cpp/winsharedutils/SimpleBrowser.cpp @@ -289,3 +289,11 @@ DECLARE_API void html_bind_function(void *web, const wchar_t *name, void (*funct auto ww = static_cast(web); ww->jsobj->bindfunction(name, function); } + +DECLARE_API HWND html_get_ie(void *web) +{ + if (!web) + return nullptr; + auto ww = static_cast(web); + return ww->GetIEServerWindow(); +} diff --git a/py/LunaTranslator/gui/usefulwidget.py b/py/LunaTranslator/gui/usefulwidget.py index 62498a07..01855765 100644 --- a/py/LunaTranslator/gui/usefulwidget.py +++ b/py/LunaTranslator/gui/usefulwidget.py @@ -1428,7 +1428,7 @@ class mshtmlWidget(abstractwebview): self.curr_url = None t = QTimer(self) t.setInterval(100) - t.timeout.connect(self.__getcurrenturl) + t.timeout.connect(self.__getcurrent) t.timeout.emit() t.start() self.add_menu(0, _TR("复制"), winsharedutils.clipboard_set) @@ -1449,11 +1449,19 @@ class mshtmlWidget(abstractwebview): func(winsharedutils.html_get_select_text(self.browser)) return windows.WNDPROCTYPE(orig)(hwnd, msg, wp, lp) - def __getcurrenturl(self): + def __getcurrent(self): _u = winsharedutils.html_get_current_url(self.browser) if self.curr_url != _u: self.curr_url = _u self.on_load.emit(_u) + if ( + windows.GetAsyncKeyState(windows.VK_CONTROL) + and windows.GetAsyncKeyState(67) + and winsharedutils.html_get_ie(self.browser) == windows.GetFocus() + ): + winsharedutils.clipboard_set( + winsharedutils.html_get_select_text(self.browser) + ) def navigate(self, url): winsharedutils.html_navigate(self.browser, url) diff --git a/py/LunaTranslator/windows.py b/py/LunaTranslator/windows.py index b1fce0a2..3b5193a5 100644 --- a/py/LunaTranslator/windows.py +++ b/py/LunaTranslator/windows.py @@ -265,6 +265,8 @@ FindWindow.argtypes = LPCWSTR, LPCWSTR FindWindow.restype = HWND SetFocus = _user32.SetFocus SetFocus.argtypes = (HWND,) +GetFocus = _user32.GetFocus +GetFocus.restype = HWND _EnumWindows = _user32.EnumWindows _EnumWindows.argtypes = WNDENUMPROC, c_void_p _ShellExecuteW = _shell32.ShellExecuteW diff --git a/py/LunaTranslator/winsharedutils.py b/py/LunaTranslator/winsharedutils.py index 1cde8cd6..ddbcbe4d 100644 --- a/py/LunaTranslator/winsharedutils.py +++ b/py/LunaTranslator/winsharedutils.py @@ -139,7 +139,9 @@ html_get_select_text.restype = c_wchar_p html_bind_function_FT = CFUNCTYPE(None, POINTER(c_wchar_p), c_int) html_bind_function = utilsdll.html_bind_function html_bind_function.argtypes = c_void_p, c_wchar_p, html_bind_function_FT - +html_get_ie = utilsdll.html_get_ie +html_get_ie.argtypes = (c_void_p,) +html_get_ie.restype = HWND _GetLnkTargetPath = utilsdll.GetLnkTargetPath _GetLnkTargetPath.argtypes = c_wchar_p, c_wchar_p, c_wchar_p, c_wchar_p