From 2fb918c1559acbd4e6030396c7e8348bbddb90e3 Mon Sep 17 00:00:00 2001 From: Cheuring Date: Thu, 31 Oct 2024 18:13:45 +0800 Subject: [PATCH 01/11] feat: add youdao translate web api --- userAHK/demo.ahk | 3 -- userAHK/main.ahk | 26 +++++++++-- userAHK/translate.ahk | 100 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 7 deletions(-) delete mode 100644 userAHK/demo.ahk create mode 100644 userAHK/translate.ahk diff --git a/userAHK/demo.ahk b/userAHK/demo.ahk deleted file mode 100644 index 1ae1c2c..0000000 --- a/userAHK/demo.ahk +++ /dev/null @@ -1,3 +0,0 @@ -keyFunc_example2(){ - msgbox, example2 -} \ No newline at end of file diff --git a/userAHK/main.ahk b/userAHK/main.ahk index 499135c..09c3901 100644 --- a/userAHK/main.ahk +++ b/userAHK/main.ahk @@ -11,8 +11,26 @@ ; 3. Save, reload Capslock+ (CapsLock+F5) ; 4. Press `CapsLock+F7` to invoke the function -#include demo.ahk +#include translate.ahk -keyFunc_example1(){ - msgbox, example1 -} +keyFunc_translate_cus(){ + global + selText:=getSelText() + if(selText) + { + ydTranslate_cus(selText) + } + else + { + ClipboardOld:=ClipboardAll + Clipboard:="" + SendInput, ^{Left}^+{Right}^{insert} + ClipWait, 0.05 + selText:=Clipboard + ydTranslate_cus(selText) + Clipboard:=ClipboardOld + } + SetTimer, setTransGuiActive, -400 + Return + +} \ No newline at end of file diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk new file mode 100644 index 0000000..a2f89f6 --- /dev/null +++ b/userAHK/translate.ahk @@ -0,0 +1,100 @@ +ydTranslate_cus(ss) +{ + if(CLSets.TTranslate.apiType = 0 || CLSets.TTranslate.appPaidID = "") + { + MsgBox, %lang_yd_free_key_unavailable_warning% + return + } + transStart_cus: + ss:=RegExReplace(ss, "\s", " ") ;把所有空白符换成空格,因为如果有回车符的话,json转换时会出错 + NativeString:=Trim(ss) + + transGui_cus: + MsgBoxStr:=NativeString?lang_yd_translating:"" + + DetectHiddenWindows, On ;可以检测到隐藏窗口 + WinGet, ifGuiExistButHide, Count, ahk_id %transGuiHwnd% + if(ifGuiExistButHide) + { + ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% + ControlFocus, , ahk_id %transEditHwnd% + WinShow, ahk_id %transGuiHwnd% + } + else + { + Gui, new, +HwndtransGuiHwnd , %lang_yd_name% + Gui, +AlwaysOnTop -Border +Caption -Disabled -LastFound -MaximizeBox -OwnDialogs -Resize +SysMenu -Theme -ToolWindow + Gui, Font, s10 w400, Microsoft YaHei UI ;设置字体 + Gui, Font, s10 w400, 微软雅黑 + gui, Add, Button, x-40 y-40 Default, OK + Gui, Add, Edit, x-2 y0 w504 h405 vTransEdit HwndtransEditHwnd -WantReturn -VScroll , %MsgBoxStr% + Gui, Color, ffffff, fefefe + Gui, +LastFound + WinSet, TransColor, ffffff 210 + Gui, Show, Center w500 h402, %lang_yd_name% + ControlFocus, , ahk_id %transEditHwnd% + SetTimer, setTransActive, 50 + } + + if(NativeString) + { + SetTimer, ydApi_cus, -1 + return + } + + Return + + ydApi_cus: + UTF8Codes:="" ;重置要发送的代码 + SetFormat, integer, H + UTF8Codes:=UTF8encode(NativeString) + if(youdaoApiString="") + { + MsgBoxStr=%lang_yd_needKey% + goto, setTransText_cus + } + + sendStr := "https://dict.youdao.com/suggest?num=6&ver=3.0&doctype=json&cache=false&le=en&q=" . UTF8encode(NativeString) + whr := ComObjCreate("Msxml2.XMLHTTP") + whr.Open("GET", sendStr, False) + + try + { + whr.Send() + } + catch + { + MsgBoxStr:=lang_yd_errorNoNet + goto, setTransText_cus + } + + responseStr := whr.ResponseText + transJson := JSON.Load(responseStr) + + if (transJson.result.code != 200) + { + MsgBoxStr := lang_yd_errorNoResults + goto, setTransText_cus + return + } + + MsgBoxStr := transJson.data.query . "`r`n`r`n" + for index, entry in transJson.data.entries + { + MsgBoxStr := MsgBoxStr . entry.entry . ": " . entry.explain . "`r`n`r`n" + } + + setTransText_cus: + ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% + ControlFocus, , ahk_id %transEditHwnd% + SetTimer, setTransActive, 50 + return + + ButtonOK_cus: + Gui, Submit, NoHide + TransEdit:=RegExReplace(TransEdit, "\s", " ") ;把所有空白符换成空格,因为如果有回车符的话,json转换时会出错 + NativeString:=Trim(TransEdit) + goto, transGui_cus + + return +} \ No newline at end of file From 938982cfbebc56f0aaebbcb48c146f34d3ec4044 Mon Sep 17 00:00:00 2001 From: Cheuring Date: Thu, 31 Oct 2024 19:43:03 +0800 Subject: [PATCH 02/11] feat: add phonetic --- userAHK/translate.ahk | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk index a2f89f6..be79f16 100644 --- a/userAHK/translate.ahk +++ b/userAHK/translate.ahk @@ -1,10 +1,5 @@ ydTranslate_cus(ss) { - if(CLSets.TTranslate.apiType = 0 || CLSets.TTranslate.appPaidID = "") - { - MsgBox, %lang_yd_free_key_unavailable_warning% - return - } transStart_cus: ss:=RegExReplace(ss, "\s", " ") ;把所有空白符换成空格,因为如果有回车符的话,json转换时会出错 NativeString:=Trim(ss) @@ -33,7 +28,6 @@ ydTranslate_cus(ss) WinSet, TransColor, ffffff 210 Gui, Show, Center w500 h402, %lang_yd_name% ControlFocus, , ahk_id %transEditHwnd% - SetTimer, setTransActive, 50 } if(NativeString) @@ -45,15 +39,41 @@ ydTranslate_cus(ss) Return ydApi_cus: - UTF8Codes:="" ;重置要发送的代码 SetFormat, integer, H - UTF8Codes:=UTF8encode(NativeString) - if(youdaoApiString="") + + ; 获取音标 + sendStr2 := "https://dict.youdao.com/jsonapi_s?doctype=json&jsonversion=4&le=en&q=" . UTF8encode(NativeString) + whr2 := ComObjCreate("Msxml2.XMLHTTP") + whr2.Open("GET", sendStr2, False) + + try { - MsgBoxStr=%lang_yd_needKey% + whr2.Send() + } + catch + { + MsgBoxStr:=MsgBoxStr . lang_yd_errorNoNet goto, setTransText_cus } + responseStr2 := whr2.ResponseText + transJson2 := JSON.Load(responseStr2) + + if (transJson2.simple.query != NativeString) + { + MsgBoxStr := MsgBoxStr . lang_yd_errorNoResults + goto, setTransText_cus + return + } + + MsgBoxStr:= % transJson2.simple.query . "`t" ;原单词 + if (transJson2.simple.word[1].ukphone) + { + ; MsgBoxStr := MsgBoxStr . "UK Phonetic: " . transJson2.simple.word[1].ukphone . "`r`n`r`n" + MsgBoxStr:=% MsgBoxStr . "[" . transJson2.simple.word[1].ukphone . "] " ;读音 + } + MsgBoxStr:= % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n" ;分隔,换行 + sendStr := "https://dict.youdao.com/suggest?num=6&ver=3.0&doctype=json&cache=false&le=en&q=" . UTF8encode(NativeString) whr := ComObjCreate("Msxml2.XMLHTTP") whr.Open("GET", sendStr, False) @@ -78,7 +98,7 @@ ydTranslate_cus(ss) return } - MsgBoxStr := transJson.data.query . "`r`n`r`n" + ; MsgBoxStr := transJson.data.query . "`r`n`r`n" for index, entry in transJson.data.entries { MsgBoxStr := MsgBoxStr . entry.entry . ": " . entry.explain . "`r`n`r`n" @@ -87,14 +107,6 @@ ydTranslate_cus(ss) setTransText_cus: ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% ControlFocus, , ahk_id %transEditHwnd% - SetTimer, setTransActive, 50 return - ButtonOK_cus: - Gui, Submit, NoHide - TransEdit:=RegExReplace(TransEdit, "\s", " ") ;把所有空白符换成空格,因为如果有回车符的话,json转换时会出错 - NativeString:=Trim(TransEdit) - goto, transGui_cus - - return } \ No newline at end of file From d19d4c7c332d7db4c34911d9f6eb246c5e79dc6a Mon Sep 17 00:00:00 2001 From: Cheuring Date: Thu, 31 Oct 2024 21:18:22 +0800 Subject: [PATCH 03/11] feat: changed blocked http request to async --- userAHK/translate.ahk | 68 +++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk index be79f16..4cd8182 100644 --- a/userAHK/translate.ahk +++ b/userAHK/translate.ahk @@ -1,11 +1,8 @@ ydTranslate_cus(ss) { - transStart_cus: ss:=RegExReplace(ss, "\s", " ") ;把所有空白符换成空格,因为如果有回车符的话,json转换时会出错 - NativeString:=Trim(ss) - - transGui_cus: - MsgBoxStr:=NativeString?lang_yd_translating:"" + global NativeString:=Trim(ss) + global MsgBoxStr:=NativeString?lang_yd_translating:"" DetectHiddenWindows, On ;可以检测到隐藏窗口 WinGet, ifGuiExistButHide, Count, ahk_id %transGuiHwnd% @@ -27,6 +24,7 @@ ydTranslate_cus(ss) Gui, +LastFound WinSet, TransColor, ffffff 210 Gui, Show, Center w500 h402, %lang_yd_name% + global transEditHwnd ControlFocus, , ahk_id %transEditHwnd% } @@ -46,6 +44,13 @@ ydTranslate_cus(ss) whr2 := ComObjCreate("Msxml2.XMLHTTP") whr2.Open("GET", sendStr2, False) + ; 获取翻译 + sendStr := "https://dict.youdao.com/suggest?num=6&ver=3.0&doctype=json&cache=false&le=en&q=" . UTF8encode(NativeString) + global whr := ComObjCreate("Msxml2.XMLHTTP") + whr.Open("GET", sendStr, True) + whr.onreadystatechange := Func("Onready_suggestion") + whr.Send() + try { whr2.Send() @@ -74,39 +79,46 @@ ydTranslate_cus(ss) } MsgBoxStr:= % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n" ;分隔,换行 - sendStr := "https://dict.youdao.com/suggest?num=6&ver=3.0&doctype=json&cache=false&le=en&q=" . UTF8encode(NativeString) - whr := ComObjCreate("Msxml2.XMLHTTP") - whr.Open("GET", sendStr, False) + Onready_suggestion() - try - { - whr.Send() - } - catch - { - MsgBoxStr:=lang_yd_errorNoNet - goto, setTransText_cus - } - responseStr := whr.ResponseText - transJson := JSON.Load(responseStr) + setTransText_cus: + ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% + ControlFocus, , ahk_id %transEditHwnd% + return + +} - if (transJson.result.code != 200) +Onready_suggestion(){ + global MsgBoxStr, NativeString, whr, transEditHwnd + if(whr.readyState != 4) { - MsgBoxStr := lang_yd_errorNoResults - goto, setTransText_cus return } - ; MsgBoxStr := transJson.data.query . "`r`n`r`n" - for index, entry in transJson.data.entries - { - MsgBoxStr := MsgBoxStr . entry.entry . ": " . entry.explain . "`r`n`r`n" + try { + responseStr := whr.ResponseText + transJson := JSON.Load(responseStr) + + if(transJson.data.query != NativeString) + { + MsgBoxStr := MsgBoxStr . lang_yd_errorNoResults + goto, setTransText_cus_ano + return + } + + ; MsgBoxStr := transJson.data.query . "`r`n`r`n" + for index, entry in transJson.data.entries + { + MsgBoxStr := MsgBoxStr . entry.entry . ": " . entry.explain . "`r`n`r`n" + } + }catch { + MsgBoxStr := MsgBoxStr . lang_yd_errorNoNet + goto, setTransText_cus_ano } - setTransText_cus: + setTransText_cus_ano: ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% ControlFocus, , ahk_id %transEditHwnd% return - } \ No newline at end of file From a8fe2eca8cb84e3bbddcffe857c8e9283143f6d0 Mon Sep 17 00:00:00 2001 From: Cheuring Date: Thu, 31 Oct 2024 21:48:54 +0800 Subject: [PATCH 04/11] fix: fixed the bug that cannot translate sentence --- userAHK/translate.ahk | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk index 4cd8182..22d3e7c 100644 --- a/userAHK/translate.ahk +++ b/userAHK/translate.ahk @@ -42,13 +42,13 @@ ydTranslate_cus(ss) ; 获取音标 sendStr2 := "https://dict.youdao.com/jsonapi_s?doctype=json&jsonversion=4&le=en&q=" . UTF8encode(NativeString) whr2 := ComObjCreate("Msxml2.XMLHTTP") - whr2.Open("GET", sendStr2, False) + whr2.Open("POST", sendStr2, False) ; 获取翻译 sendStr := "https://dict.youdao.com/suggest?num=6&ver=3.0&doctype=json&cache=false&le=en&q=" . UTF8encode(NativeString) global whr := ComObjCreate("Msxml2.XMLHTTP") whr.Open("GET", sendStr, True) - whr.onreadystatechange := Func("Onready_suggestion") + whr.onreadystatechange := Func("onReady_suggestion") whr.Send() try @@ -57,7 +57,7 @@ ydTranslate_cus(ss) } catch { - MsgBoxStr:=MsgBoxStr . lang_yd_errorNoNet + MsgBoxStr:= lang_yd_errorNoNet goto, setTransText_cus } @@ -66,7 +66,11 @@ ydTranslate_cus(ss) if (transJson2.simple.query != NativeString) { - MsgBoxStr := MsgBoxStr . lang_yd_errorNoResults + MsgBoxStr := lang_yd_errorNoResults + if(transJson2.fanyi){ + MsgBoxStr := % transJson2.fanyi.input . "`r`n`r`n" . lang_yd_trans . "`r`n" ;分隔,换行 + MsgBoxStr := % MsgBoxStr . transJson2.fanyi.tran . "`r`n`r`n" + } goto, setTransText_cus return } @@ -79,7 +83,7 @@ ydTranslate_cus(ss) } MsgBoxStr:= % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n" ;分隔,换行 - Onready_suggestion() + onReady_suggestion() setTransText_cus: @@ -89,7 +93,7 @@ ydTranslate_cus(ss) } -Onready_suggestion(){ +onReady_suggestion(){ global MsgBoxStr, NativeString, whr, transEditHwnd if(whr.readyState != 4) { @@ -102,7 +106,6 @@ Onready_suggestion(){ if(transJson.data.query != NativeString) { - MsgBoxStr := MsgBoxStr . lang_yd_errorNoResults goto, setTransText_cus_ano return } From b43846b8d3876a60d8cc9a6c5b698c99c782815f Mon Sep 17 00:00:00 2001 From: Cheuring Date: Fri, 1 Nov 2024 20:30:21 +0800 Subject: [PATCH 05/11] feat: removed one request to simplify the data --- userAHK/translate.ahk | 97 ++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 62 deletions(-) diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk index 22d3e7c..47776f3 100644 --- a/userAHK/translate.ahk +++ b/userAHK/translate.ahk @@ -1,8 +1,8 @@ ydTranslate_cus(ss) { ss:=RegExReplace(ss, "\s", " ") ;把所有空白符换成空格,因为如果有回车符的话,json转换时会出错 - global NativeString:=Trim(ss) - global MsgBoxStr:=NativeString?lang_yd_translating:"" + NativeString:=Trim(ss) + MsgBoxStr:=NativeString?lang_yd_translating:"" DetectHiddenWindows, On ;可以检测到隐藏窗口 WinGet, ifGuiExistButHide, Count, ahk_id %transGuiHwnd% @@ -24,7 +24,6 @@ ydTranslate_cus(ss) Gui, +LastFound WinSet, TransColor, ffffff 210 Gui, Show, Center w500 h402, %lang_yd_name% - global transEditHwnd ControlFocus, , ahk_id %transEditHwnd% } @@ -40,20 +39,13 @@ ydTranslate_cus(ss) SetFormat, integer, H ; 获取音标 - sendStr2 := "https://dict.youdao.com/jsonapi_s?doctype=json&jsonversion=4&le=en&q=" . UTF8encode(NativeString) - whr2 := ComObjCreate("Msxml2.XMLHTTP") - whr2.Open("POST", sendStr2, False) - - ; 获取翻译 - sendStr := "https://dict.youdao.com/suggest?num=6&ver=3.0&doctype=json&cache=false&le=en&q=" . UTF8encode(NativeString) - global whr := ComObjCreate("Msxml2.XMLHTTP") - whr.Open("GET", sendStr, True) - whr.onreadystatechange := Func("onReady_suggestion") - whr.Send() + sendStr := "https://dict.youdao.com/jsonapi_s?doctype=json&jsonversion=4&le=en&q=" . UTF8encode(NativeString) . "_" + whr := ComObjCreate("Msxml2.XMLHTTP") + whr.Open("POST", sendStr, False) try { - whr2.Send() + whr.Send() } catch { @@ -61,66 +53,47 @@ ydTranslate_cus(ss) goto, setTransText_cus } - responseStr2 := whr2.ResponseText - transJson2 := JSON.Load(responseStr2) + responseStr := whr.ResponseText + transJson := JSON.Load(responseStr) - if (transJson2.simple.query != NativeString) - { - MsgBoxStr := lang_yd_errorNoResults - if(transJson2.fanyi){ - MsgBoxStr := % transJson2.fanyi.input . "`r`n`r`n" . lang_yd_trans . "`r`n" ;分隔,换行 - MsgBoxStr := % MsgBoxStr . transJson2.fanyi.tran . "`r`n`r`n" - } - goto, setTransText_cus - return - } + MsgBoxStr := % NativeString . " " - MsgBoxStr:= % transJson2.simple.query . "`t" ;原单词 - if (transJson2.simple.word[1].ukphone) - { - ; MsgBoxStr := MsgBoxStr . "UK Phonetic: " . transJson2.simple.word[1].ukphone . "`r`n`r`n" - MsgBoxStr:=% MsgBoxStr . "[" . transJson2.simple.word[1].ukphone . "] " ;读音 - } - MsgBoxStr:= % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n" ;分隔,换行 + if(transJson.fanyi){ + MsgBoxStr := % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n`r`n" ;分隔,换行 + MsgBoxStr := % MsgBoxStr . transJson.fanyi.tran . "`r`n`r`n" - onReady_suggestion() + goto, setTransText_cus + } + if(transJson.ec){ + if(transJson.ec.word.ukphone){ + MsgBoxStr := % MsgBoxStr . "[" . transJson.ec.word.ukphone . "] " ;读音 + } - setTransText_cus: - ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% - ControlFocus, , ahk_id %transEditHwnd% - return + MsgBoxStr := % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n`r`n" ;分隔,换行 -} + for index , web_tran in transJson.ec.web_trans + { + if(index > 1) { + MsgBoxStr:=% MsgBoxStr . A_Space . ";" . A_Space + } -onReady_suggestion(){ - global MsgBoxStr, NativeString, whr, transEditHwnd - if(whr.readyState != 4) - { - return - } + MsgBoxStr := % MsgBoxStr . web_tran + } - try { - responseStr := whr.ResponseText - transJson := JSON.Load(responseStr) + if(transJson.phrs){ + MsgBoxStr := % MsgBoxStr . "`r`n`r`n" . lang_yd_phrase . "`r`n`r`n" ;分隔,换行 - if(transJson.data.query != NativeString) - { - goto, setTransText_cus_ano - return - } - - ; MsgBoxStr := transJson.data.query . "`r`n`r`n" - for index, entry in transJson.data.entries - { - MsgBoxStr := MsgBoxStr . entry.entry . ": " . entry.explain . "`r`n`r`n" + for index, entry in transJson.phrs.phrs + { + MsgBoxStr := MsgBoxStr . entry.headword . ": " . entry.translation . "`r`n`r`n" + } } - }catch { - MsgBoxStr := MsgBoxStr . lang_yd_errorNoNet - goto, setTransText_cus_ano + + goto, setTransText_cus } - setTransText_cus_ano: + setTransText_cus: ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% ControlFocus, , ahk_id %transEditHwnd% return From 52a0c29db4f6d106a316b142732eac43b2679096 Mon Sep 17 00:00:00 2001 From: Cheuring Date: Fri, 1 Nov 2024 20:35:38 +0800 Subject: [PATCH 06/11] fix: add no result error --- userAHK/translate.ahk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk index 47776f3..cb6c421 100644 --- a/userAHK/translate.ahk +++ b/userAHK/translate.ahk @@ -93,6 +93,8 @@ ydTranslate_cus(ss) goto, setTransText_cus } + MsgBoxStr := lang_yd_errorNoResults + setTransText_cus: ControlSetText, , %MsgBoxStr%, ahk_id %transEditHwnd% ControlFocus, , ahk_id %transEditHwnd% From 8806d61aa11e00bc385b9ec3b985e8e8dc6e9eba Mon Sep 17 00:00:00 2001 From: Cheuring Date: Fri, 1 Nov 2024 20:46:31 +0800 Subject: [PATCH 07/11] fix: add usphonetic --- userAHK/translate.ahk | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk index cb6c421..049029d 100644 --- a/userAHK/translate.ahk +++ b/userAHK/translate.ahk @@ -56,7 +56,7 @@ ydTranslate_cus(ss) responseStr := whr.ResponseText transJson := JSON.Load(responseStr) - MsgBoxStr := % NativeString . " " + MsgBoxStr := % NativeString if(transJson.fanyi){ MsgBoxStr := % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n`r`n" ;分隔,换行 @@ -66,8 +66,12 @@ ydTranslate_cus(ss) } if(transJson.ec){ + if(transJson.ec.word.usphone){ + MsgBoxStr := % MsgBoxStr . " " . "[" . transJson.ec.word.usphone . "] " ;读音 + } + if(transJson.ec.word.ukphone){ - MsgBoxStr := % MsgBoxStr . "[" . transJson.ec.word.ukphone . "] " ;读音 + MsgBoxStr := % MsgBoxStr . " " . "[" . transJson.ec.word.ukphone . "] " ;读音 } MsgBoxStr := % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n`r`n" ;分隔,换行 From 642a0b5ae4cdc8cdce1026ba1cff3dd89369d733 Mon Sep 17 00:00:00 2001 From: Cheuring Date: Fri, 1 Nov 2024 21:04:17 +0800 Subject: [PATCH 08/11] chroes: changed the ending symbol to reduce the error occurrence --- userAHK/translate.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/userAHK/translate.ahk b/userAHK/translate.ahk index 049029d..1d347d4 100644 --- a/userAHK/translate.ahk +++ b/userAHK/translate.ahk @@ -39,7 +39,7 @@ ydTranslate_cus(ss) SetFormat, integer, H ; 获取音标 - sendStr := "https://dict.youdao.com/jsonapi_s?doctype=json&jsonversion=4&le=en&q=" . UTF8encode(NativeString) . "_" + sendStr := "https://dict.youdao.com/jsonapi_s?doctype=json&jsonversion=4&le=en&q=" . UTF8encode(NativeString) . "~" whr := ComObjCreate("Msxml2.XMLHTTP") whr.Open("POST", sendStr, False) @@ -56,7 +56,7 @@ ydTranslate_cus(ss) responseStr := whr.ResponseText transJson := JSON.Load(responseStr) - MsgBoxStr := % NativeString + MsgBoxStr := NativeString if(transJson.fanyi){ MsgBoxStr := % MsgBoxStr . "`r`n`r`n" . lang_yd_trans . "`r`n`r`n" ;分隔,换行 From cc324146b6ba90630713baecfd83870ccbd39160 Mon Sep 17 00:00:00 2001 From: Cheuring Date: Fri, 1 Nov 2024 22:48:39 +0800 Subject: [PATCH 09/11] fix: add demo.ahk back and add comment on keyFunc_translate_cus --- userAHK/demo.ahk | 3 +++ userAHK/main.ahk | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 userAHK/demo.ahk diff --git a/userAHK/demo.ahk b/userAHK/demo.ahk new file mode 100644 index 0000000..9dbe30f --- /dev/null +++ b/userAHK/demo.ahk @@ -0,0 +1,3 @@ +keyFunc_example2(){ + msgbox, example2 +} \ No newline at end of file diff --git a/userAHK/main.ahk b/userAHK/main.ahk index 09c3901..32e6c72 100644 --- a/userAHK/main.ahk +++ b/userAHK/main.ahk @@ -11,8 +11,24 @@ ; 3. Save, reload Capslock+ (CapsLock+F5) ; 4. Press `CapsLock+F7` to invoke the function +#include demo.ahk + +keyFunc_example1(){ + msgbox, example1 +} + +; end demo + + #include translate.ahk + +; This function calls the Youdao translation web API to achieve free translation functionality. +; It is an unconventional method, but I hope it can give you some inspiration. +; add below setting under the [Keys] section in `CapsLock+settings.ini`: +; caps_f9=keyFunc_translate_cus +; 3. Save, reload Capslock+ (CapsLock+F5) +; 4. Press `CapsLock+F9` to invoke the function keyFunc_translate_cus(){ global selText:=getSelText() From f03da6459372f4bead907ccf804b05569fa1d06d Mon Sep 17 00:00:00 2001 From: Cheuring Date: Fri, 1 Nov 2024 22:50:27 +0800 Subject: [PATCH 10/11] chroes: fix the comments on keyFunc_translate_cus() --- userAHK/main.ahk | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/userAHK/main.ahk b/userAHK/main.ahk index 32e6c72..d3b4507 100644 --- a/userAHK/main.ahk +++ b/userAHK/main.ahk @@ -25,10 +25,11 @@ keyFunc_example1(){ ; This function calls the Youdao translation web API to achieve free translation functionality. ; It is an unconventional method, but I hope it can give you some inspiration. -; add below setting under the [Keys] section in `CapsLock+settings.ini`: +; How to use: +; 1. add below setting under the [Keys] section in `CapsLock+settings.ini`: ; caps_f9=keyFunc_translate_cus -; 3. Save, reload Capslock+ (CapsLock+F5) -; 4. Press `CapsLock+F9` to invoke the function +; 2. Save, reload Capslock+ (CapsLock+F5) +; 3. Press `CapsLock+F9` to invoke the function keyFunc_translate_cus(){ global selText:=getSelText() From e2b5d15601fffac7f9a46374df326d523b543f19 Mon Sep 17 00:00:00 2001 From: Cheuring Date: Fri, 1 Nov 2024 23:02:45 +0800 Subject: [PATCH 11/11] chroes: fixed the identation --- userAHK/demo.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/userAHK/demo.ahk b/userAHK/demo.ahk index 9dbe30f..1ae1c2c 100644 --- a/userAHK/demo.ahk +++ b/userAHK/demo.ahk @@ -1,3 +1,3 @@ keyFunc_example2(){ - msgbox, example2 + msgbox, example2 } \ No newline at end of file