Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoEnv
- #SingleInstance FORCE
- #Persistent
- SetCapsLockState, Off
- SetTimer, RestartScript, 1200000
- SetBatchLines, -1
- ; Check every second if CapsLock is off
- SetTimer, keepCapsLockOff, 1000
- keepCapsLockOff()
- {
- SetCapsLockState Off
- }
- Global guiHandle
- Global Extend:=200
- Global lastExtended:=0 , Extended:=0
- Global guiTitle:="Tu Dien Han-Viet"
- Global guiW:=600
- Global guiH:=A_ScreenHeight-300
- ;~ Global spVoice:=ComObjCreate("SAPI.SpVoice")
- ;~ SpVoice.Voice:=SpVoice.GetVoices("Name=Microsoft Heami Desktop").Item(0)
- _InitGUI()
- return
- RestartScript:
- ;~ MsgBox, 4, Restarting dictionary script, Restarting dictionary script. Select 'no' in the next 10 seconds to cancel. Otherwise wait 10 seconds or hit 'yes'., 10
- ;~ IfMsgBox, No
- ;~ return
- Run, "%A_AhkPath%" /r "%A_ScriptFullPath%"
- #iF,% WinExist("ahk_id" guiHandle)
- ~*LShift::
- GuiEscape:
- Gui,Hide
- DllCall("psapi.dll\EmptyWorkingSet","UInt",-1)
- return
- #iF
- ;~ #iF,% WinActive("ahk_id" guiHandle)
- ;~ Enter::
- ;~ Temp:=Clipboard
- ;~ Clipboard:=""
- ;~ Send ^c
- ;~ ClipWait 2
- ;~ iF ErrorLevel
- ;~ {
- ;~ Clipboard:=Temp
- ;~ return
- ;~ }
- ;~ TextToSpeech:=Trim(Clipboard)
- ;~ Clipboard:=Temp
- ;~ spVoice.Speak(TextToSpeech,0x1|0x2)
- ;~ return
- #iF
- ;^1::bool := !bool
- Ctrl::
- ; if(bool) {
- Temp:=Clipboard
- Clipboard:=""
- Send ^c
- ClipWait 2
- iF ErrorLevel
- {
- Clipboard:=Temp
- return
- }
- ;}
- ;LAlt::
- Text:=Trim(Clipboard)
- Clipboard:=Temp
- WinGet,MinMax,MinMax,ahk_id %guiHandle%
- iF MinMax=-1
- WinRestore,ahk_id %guiHandle%
- iF StrLen(Text)>1000
- return
- GuiControl,Show,WB
- ;~ GuiControl,Hide,WB2
- ;~ GuiControl,Hide,WB3
- GuiControl,Focus,WB
- DetectHiddenWindows OFF
- GuiControl,Hide,WBedit
- GuiControl,Move,WB,% "y0 h" guiH-40
- ;~ GuiControl,Move,WB2,% "y0 h" guiH-40
- ;~ GuiControl,Move,WB3,% "y0 h" guiH-40
- iF not WinExist("ahk_id " guiHandle)
- {
- ;~ iF not Pos
- ;~ {
- Pos:=ActiveMonitorCoordinates()
- x := Pos[3]+Pos[1] - guiW - 160
- y := 0
- Gui,Show,% "x" x " y" y " w" guiW+(lastExtended*Extend) " h" guiH,% guiTitle
- ;~ }
- ;~ else
- ;~ {
- ;~ DetectHiddenWindows ON
- ;~ WinGetPos,guiX,,,,ahk_id %guiHandle%
- ;~ Gui,Show,% "w" guiW " x" guiX+(lastExtended*Extend) " h" guiH,% guiTitle
- ;~ }
- }
- else
- {
- WinGetPos,guiX,,,,ahk_id %guiHandle%
- Gui,Show,% "w" guiW " x" guiX+(lastExtended*Extend) " h" guiH,% guiTitle
- }
- Try WB.Navigate("https://dict.naver.com/vikodict/vietnamese/#/search?query=" UrlEncode(Text))
- Catch
- Try WB.Navigate("https://dict.naver.com/vikodict/vietnamese/#/search?query=" UrlEncode2(Text))
- ;~ Try WB2.Navigate("http://m.endic.naver.com/search.nhn?searchOption=all&query=" UrlEncode(Text)) ;English
- ;~ Catch
- ;~ WB2.Navigate("http://m.endic.naver.com/search.nhn?searchOption=all&query=" UrlEncode2(Text)) ;English
- ;~ Try WB3.Navigate("https://ko.dict.naver.com/#/search?query=" UrlEncode(Text)) ;Korean
- ;~ Catch
- ;~ WB3.Navigate("https://ko.dict.naver.com/#/search?query=" UrlEncode2(Text)) ;Korean
- ;SetTimer,Translate,-0
- return
- GuiSize:
- iF A_EventInfo=1 ;The window has been minimized, no action needed
- return
- DetectHiddenWindows OFF
- iF WinExist("ahk_id " guiHandle)
- {
- ;WinGetClientSize(guiHandle,newW,newH)
- WinGetPos,,,newW,,ahk_id %guiHandle%
- ;GuiControl,Move,Button1,% "x" 0 " w" guiW/3+(Extended*Extend)
- ;GuiControl,Move,Button2,% "x" (guiW/1.5)+(Extended*Extend)
- ;GuiControl,Move,Button3,% "x" (guiW/3)+(Extended*Extend)
- GuiControl,Move,Button1,% "x" 0 " w" (guiW+Extended*Extend) ;"x" 0+(Extended*Extend)
- ;~ GuiControl,Move,Button2,% "x" (guiW+Extended*Extend)/3 " w" (guiW+Extended*Extend)/3
- ;~ GuiControl,Move,Button3,% "x" (guiW+Extended*Extend)/3*2 " w" (guiW+Extended*Extend)/3
- }
- return
- ActiveMonitorCoordinates() ;by Ħakito
- {
- ;~ SysGet,PhysicalMonitors,80
- ;~ CoordMode,Mouse,Screen
- ;~ MouseGetPos,mouseX,mouseY
- ;~ Loop %PhysicalMonitors%
- ;~ {
- ;~ SysGet,Position,Monitor,%A_Index%
- ;~ iF(mouseX>=PositionLeft and mouseY>=PositionTop and mouseX<PositionRight and mouseY<PositionBottom)
- ;~ {
- ;~ Monitor:=A_Index
- ;~ }
- ;~ }
- ;~ iF(Monitor="")
- ;~ Monitor:=0
- Monitor :=1
- SysGet Pos,Monitor,%Monitor%
- return [PosLeft,PosTop,PosRight-PosLeft,PosBottom-PosTop]
- }
- _InitGUI() {
- Global
- Local Pos,x,y
- Pos:=ActiveMonitorCoordinates()
- x := Pos[3]+Pos[1] - guiW - 10
- y :=0
- Gui,+AlwaysOnTop +HWNDguiHandle
- Gui,Margin, 0, 0
- Gui,Add,ActiveX,% "x0 y63 w" guiW " h" guiH-103 " vWB", Shell.Explorer ;Vietnamese
- ;~ Gui,Add,ActiveX,% "x0 y63 w" guiW " h" guiH-103 " vWB2 Hidden", Shell.Explorer ;English
- ;~ Gui,Add,ActiveX,% "x0 y63 w" guiW " h" guiH-103 " vWB3 Hidden", Shell.Explorer ;Korean
- WB.Silent:=True
- ;~ WB2.Silent:=True , WB3.Silent:=True
- ;Gui, Color, Black
- Gui,Add,Button,% "h40 x0 y" guiH-40 " w" guiW , Hien Lucy 안녕하세요!
- ;~ Gui,Add,Button,% "h40 x0 y" guiH-40 " w" guiW/3 " gChangeLanguage vButton2",English
- ;~ Gui,Add,Button,% "h40 x0 y" guiH-40 " w" guiW/3 " gChangeLanguage vButton3",Korean
- Gui,Font, cFFFFFF s12 w600,Sans Serif
- Gui,Color,c00C73C,c00C73C
- ;Gui, Color, 4D00FF
- ;~ Gui,Add,Edit,% "x3 y3 w" guiW-6 " h" 60 " vWBedit +0x100 +0x200 -E0x200 -HScroll -VScroll" ;Translation to English
- Gui,Show,Hide x%x% y%y% w%guiW% h%guiH%,% guiTitle
- WB.Navigate("about:blank")
- ;~ WB2.Navigate("about:blank")
- ;~ WB3.Navigate("about:blank")
- While WB.readystate != 4 or WB.busy
- Sleep 5
- ComObjConnect(WB, "WB_")
- ;~ ComObjConnect(WB2, "WB_")
- ;~ ComObjConnect(WB3, "WB_")
- ComObjConnect(WBdocument:=WB.document, "WBdocument_")
- ;~ ComObjConnect(WB2document:=WB2.document, "WB2document_")
- ;~ ComObjConnect(WB3document:=WB3.document, "WB3document_")
- WB.Navigate("https://dict.naver.com/vikodict/vietnamese/#/search?query=loading") ;Vietnamese
- ;WB2.Navigate("http://m.endic.naver.com/search.nhn?searchOption=all&query=loading") ;English
- ;WB3.Navigate("https://ko.dict.naver.com/search/all/0/loading/?format=HTML&isMobile=true&isReDirect=false") ;Korean
- return
- }
- ;~ ChangeLanguage:
- ;~ Critical
- ;~ iF(A_GuiControl="Button1") ;Vietnamese
- ;~ {
- ;~ GuiControl,Show,WB
- ;~ GuiControl,Hide,WB2
- ;~ GuiControl,Hide,WB3
- ;~ GuiControl,Focus,WB
- ;~ }
- ;~ else iF(A_GuiControl="Button2") ;English
- ;~ {
- ;~ GuiControl,Hide,WB
- ;~ GuiControl,Show,WB2
- ;~ GuiControl,Hide,WB3
- ;~ GuiControl,Focus,WB2
- ;~ ;WB2.Document.Write("") ;Clears the page
- ;~ }
- ;~ else iF(A_GuiControl="Button3") ;Korean
- ;~ {
- ;~ GuiControl,Hide,WB
- ;~ GuiControl,Hide,WB2
- ;~ GuiControl,Show,WB3
- ;~ GuiControl,Focus,WB3
- ;~ ;WB3.Document.Write("") ;Clears the page
- ;~ }
- ;~ return
- WB_NavigateComplete2(pDisp,URL,WB)
- {
- Global
- Local divTags:=WB.Document.All.Tags("div")
- Loop % divTags.length
- {
- iF divTags[A_Index-1].ClassName="mykeyword_wrap opened"
- {
- divTags[A_Index-1].OuterHtml:=""
- return ;Returns nothing
- }
- }
- }
- WBdocument_OnKeyPress(p*) ;By jethrow, it fixes Ctrl+X/C/V etc - https://autohotkey.com/board/topic/76777-help-with-copy-and-pasting-with-shellexplorer/
- {
- Global
- Static Keys:={1:"selectall", 3:"copy", 13:"enter", 22:"paste", 24:"cut", 25:"redo", 26:"undo"}
- Local keyCode
- iF Keys.HasKey(keyCode:=WBdocument.parentWindow.event.keyCode)
- WBdocument.ExecCommand(Keys[keyCode])
- }
- ;~ WB2document_OnKeyPress(p*) ;By jethrow, it fixes Ctrl+X/C/V etc - https://autohotkey.com/board/topic/76777-help-with-copy-and-pasting-with-shellexplorer/
- ;~ {
- ;~ Global
- ;~ Static Keys:={1:"selectall", 3:"copy", 13:"enter", 22:"paste", 24:"cut", 25:"redo", 26:"undo"}
- ;~ Local keyCode
- ;~ iF Keys.HasKey(keyCode:=WB2document.parentWindow.event.keyCode)
- ;~ WB2document.ExecCommand(Keys[keyCode])
- ;~ }
- ;~ WB3document_OnKeyPress(p*) ;By jethrow, it fixes Ctrl+X/C/V etc - https://autohotkey.com/board/topic/76777-help-with-copy-and-pasting-with-shellexplorer/
- ;~ {
- ;~ Global
- ;~ Static Keys:={1:"selectall", 3:"copy", 13:"enter", 22:"paste", 24:"cut", 25:"redo", 26:"undo"}
- ;~ Local keyCode
- ;~ iF Keys.HasKey(keyCode:=WB3document.parentWindow.event.keyCode)
- ;~ WB3document.ExecCommand(Keys[keyCode])
- ;~ }
- UrlEncode2(Str, All := False) ;From https://autohotkey.com/boards/viewtopic.php?t=2477
- {
- Static doc := ComObjCreate("HTMLfile")
- Try
- {
- doc.write("<body><script>document.body.innerText = encodeURI" . (All ? "Component" : "") . "(""" . Str . """);</script>")
- Return, doc.body.innerText, doc.body.innerText := ""
- }
- }
- UrlDecode2(Str)
- {
- Static doc := ComObjCreate("HTMLfile")
- Try
- {
- doc.write("<body><script>document.body.innerText = decodeURIComponent(""" . Str . """);</script>")
- Return, doc.body.innerText, doc.body.innerText := ""
- }
- }
- ;########################################################################### ###########################################################################
- ;########################################################################### TRANSLATE ###########################################################################
- ;########################################################################### ###########################################################################
- Translate:
- Critical OFF
- Translation:=GoogleTranslate(Text).main
- GuiControl,,WBedit,% Translation
- ;Gui,Show,NA,% "EN: " Translation
- return
- CapsLock::
- Temp:=Clipboard
- ;~ Clipboard:=""
- ;~ SendInput ^c
- ;~ ClipWait 2
- ;~ iF ErrorLevel
- ;~ {
- ;~ Clipboard:=Temp
- ;~ Return
- ;~ }
- ;~ Text:=Clipboard
- Clipboard:=Temp
- DetectHiddenWindows OFF
- GuiControl,Show,WBedit
- GuiControl,Move,WB,% "y63 h" guiH-103
- ;~ GuiControl,Move,WB2,% "y63 h" guiH-103
- ;~ GuiControl,Move,WB3,% "y63 h" guiH-103
- iF not WinExist("ahk_id " guiHandle)
- {
- DetectHiddenWindows ON
- WinGetPos,guiX,,,,ahk_id %guiHandle%
- Gui,Show,% "w" guiW " x" guiX+(Extended*Extend) " h63",% "Translation to English"
- lastExtended:=Extended:=0
- }
- Goto,Translate
- return
- ;~ /*
- ;~ F12::
- ;~ Result:=GoogleTranslate("테스트")
- ;~ Msgbox % Result.From
- ;~ return
- ;~ */
- GoogleTranslate(str, from := "auto", to := "en")
- {
- JSON:=new JSON
- JS:=JSON.JS
- JS.(GetJScript())
- sJson:=SendRequest(JS,str,to,from)
- oJSON:=JSON.Parse(sJson)
- if !IsObject(oJSON[2]) {
- for k, v in oJSON[1]
- trans .= v[1]
- }
- else {
- MainTransText := oJSON[1, 1, 1]
- for k, v in oJSON[2] {
- trans .= "`n+"
- for i, txt in v[2]
- trans .= (MainTransText = txt ? "" : "`n" . txt)
- }
- }
- if !IsObject(oJSON[2])
- MainTransText := trans := Trim(trans, ",+`n ")
- else
- trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")
- from := oJSON[3]
- trans := Trim(trans, ",+`n ")
- Return {main: MainTransText, full: trans, from: from, sJson: sJson}
- }
- SendRequest(JS, str, tl, sl) {
- ComObjError(false)
- url := "https://translate.google.com/translate_a/single?client=t&sl="
- . sl . "&tl=" . tl . "&hl=" . tl
- . "&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=3&tsel=3&pc=1&kc=2"
- . "&tk=" . JS.("tk").(str)
- body := "q=" UrlEncode(str)
- contentType := "application/x-www-form-urlencoded;charset=utf-8"
- userAgent := "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
- Return JSON.GetFromUrl(url, body, contentType, userAgent)
- }
- UrlEncode(str, encoding := "UTF-8") {
- VarSetCapacity(var, StrPut(str, encoding))
- StrPut(str, &var, encoding)
- While code := NumGet(Var, A_Index - 1, "UChar") {
- bool := (code > 0x7F || code < 0x30 || code = 0x3D)
- UrlStr .= bool ? "%" . Format("{:02X}", code) : Chr(code)
- }
- Return UrlStr
- }
- GetJScript()
- {
- script =
- (
- var TKK = ((function() {
- var a = 561666268;
- var b = 1526272306;
- return 406398 + '.' + (a + b);
- })());
- function b(a, b) {
- for (var d = 0; d < b.length - 2; d += 3) {
- var c = b.charAt(d + 2),
- c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c),
- c = "+" == b.charAt(d + 1) ? a >>> c : a << c;
- a = "+" == b.charAt(d) ? a + c & 4294967295 : a ^ c
- }
- return a
- }
- function tk(a) {
- for (var e = TKK.split("."), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) {
- var c = a.charCodeAt(f);
- 128 > c ? g[d++] = c : (2048 > c ? g[d++] = c >> 6 | 192 : (55296 == (c & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ?
- (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240,
- g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128)
- }
- a = h;
- for (d = 0; d < g.length; d++) a += g[d], a = b(a, "+-a^+6");
- a = b(a, "+-3^+b+-f");
- a ^= Number(e[1]) || 0;
- 0 > a && (a = (a & 2147483647) + 2147483648);
- a `%= 1E6;
- return a.toString() + "." + (a ^ h)
- }
- )
- Return script
- }
- class JSON
- {
- static JS := JSON._GetJScripObject()
- Parse(JsonString) {
- try oJSON := this.JS.("(" JsonString ")")
- catch {
- MsgBox, Wrong JsonString!
- Return
- }
- Return this._CreateObject(oJSON)
- }
- GetFromUrl(url, body := "", contentType := "", userAgent := "") {
- XmlHttp := ComObjCreate("Microsoft.XmlHttp")
- XmlHttp.Open("GET", url, false)
- ( contentType && XmlHttp.SetRequestHeader("Content-Type", contentType) )
- ( userAgent && XmlHttp.SetRequestHeader("User-Agent", userAgent) )
- XmlHttp.Send(body)
- Return XmlHttp.ResponseText
- }
- _GetJScripObject() {
- VarSetCapacity(tmpFile, (MAX_PATH := 260) << !!A_IsUnicode, 0)
- DllCall("GetTempFileName", Str, A_Temp, Str, "AHK", UInt, 0, Str, tmpFile)
- FileAppend,
- (
- <component>
- <public><method name='eval'/></public>
- <script language='JScript'></script>
- </component>
- ), % tmpFile
- JS := ObjBindMethod( ComObjGet("script:" . tmpFile), "eval" )
- FileDelete, % tmpFile
- JSON._AddMethods(JS)
- Return JS
- }
- _AddMethods(ByRef JS) {
- JScript =
- (
- Object.prototype.GetKeys = function () {
- var keys = []
- for (var k in this)
- if (this.hasOwnProperty(k))
- keys.push(k)
- return keys
- }
- Object.prototype.IsArray = function () {
- var toStandardString = {}.toString
- return toStandardString.call(this) == '[object Array]'
- }
- )
- JS.("delete ActiveXObject; delete GetObject;")
- JS.(JScript)
- }
- _CreateObject(ObjJS) {
- res := ObjJS.IsArray()
- if (res = "")
- Return ObjJS
- else if (res = -1) {
- obj := []
- Loop % ObjJS.length
- obj[A_Index] := this._CreateObject(ObjJS[A_Index - 1])
- }
- else if (res = 0) {
- obj := {}
- keys := ObjJS.GetKeys()
- Loop % keys.length
- k := keys[A_Index - 1], obj[k] := this._CreateObject(ObjJS[k])
- }
- Return obj
- }
- }
- ;#####################################################################################WinGetClientSize
- WinGetClientSize(windowID:="A",ByRef Width:="OutputW",ByRef Height:="OutputH") ;by jNizM
- {
- DetectHiddenWindows ON
- iF(windowID="A" or windowID="Active")
- WinGet windowID,ID,A
- VarSetCapacity(Output,16)
- DllCall("GetClientRect","uint",windowID,"uint",&Output)
- Width:=NumGet(Output,8,"int")
- Height:=NumGet(Output,12,"int")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement