Help with translation script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

Help with translation script

04 May 2021, 15:12

This is the translation code that I got with your help

Code: Select all

SetKeyDelay, -1, 0
SetDefaultMouseSpeed, 0
Gui -Resize -
Gui  +LastFound
height := A_ScreenHeight-485
Gui, Add, Text, x15, ....
Gui, Add, Edit, r1 vMyEdit w130,
Gui, Add, Text, x15, ...
Gui, Add, Edit, r1 vMyEdit2 w130,
Gui, Add, Text, x30, From
Gui, Add, Edit, r1 vMyEdit3 w130,
Gui, Add, Text, x30, To
Gui, Add, Edit, r1 vMyEdit4 w130,
Gui, Show, x450 y%height%
CoordMode, Mouse screen
SetTimer, Check, 20
return

Check:
MouseGetPos,xx,yy
Tooltip %xx%`,%yy%
return
GoogleTranslate(str, from := "auto", to := "en")  {
   static JS := CreateScriptObj(), _ := JS.( GetJScript() ) := JS.("delete ActiveXObject; delete GetObject;")
   
   json := SendRequest(JS, str, to, from, proxy := "")
   oJSON := JS.("(" . json . ")")

   if !IsObject(oJSON[1])  {
      Loop % oJSON[0].length
         trans .= oJSON[0][A_Index - 1][0]
   }
   else  {
      MainTransText := oJSON[0][0][0]
      Loop % oJSON[1].length  {
         trans .= "`n+"
         obj := oJSON[1][A_Index-1][1]
         Loop % obj.length  {
            txt := obj[A_Index - 1]
            trans .= (MainTransText = txt ? "" : "`n" txt)
         }
      }
   }
   if !IsObject(oJSON[1])
      MainTransText := trans := Trim(trans, ",+`n ")
   else
      trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")

   from := oJSON[2]
   trans := Trim(trans, ",+`n ")
   Return trans
}

SendRequest(JS, str, tl, sl, proxy) {
   static http
   ComObjError(false)
   if !http
   {
      http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
      ( proxy && http.SetProxy(2, proxy) )
      http.open( "get", "https://translate.google.com", 1 )
      http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
      http.send()
      http.WaitForResponse(-1)
   }
   http.open( "POST", "https://translate.google.com/translate_a/single?client=webapp&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=0&ssel=0&tsel=0&pc=1&kc=1"
      . "&tk=" . JS.("tk").(str), 1 )

   http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
   http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
   http.send("q=" . URIEncode(str))
   http.WaitForResponse(-1)
   Return http.responsetext
}

URIEncode(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
}

CreateScriptObj() {
   static doc
   doc := ComObjCreate("htmlfile")
   doc.write("<meta http-equiv='X-UA-Compatible' content='IE=9'>")
   Return ObjBindMethod(doc.parentWindow, "eval")
}
;=============================The Script=======================


F1::
gui,submit,nohide  ;updates gui variables with information from gui

coords1 := StrSplit(myedit,","," ") ;split text string
coords2 := StrSplit(myedit2,","," ")
cx1 := coords1[1], cy1 := coords1[2]
cx2 := coords2[1], cy2 := coords2[2]

mousemove,%cx1%,%cy1%
	ClipSave := ClipboardAll
	Clipboard := ""
	Send, ^{Click}
	ClipWait, 1
	if ErrorLevel
		return
	Clipboard := GoogleTranslate(Clipboard, "ar", "en")
click,left,%cx2%,%cy2%
	Send, %Clipboard% {Enter}
	Clipboard := ClipSave
	return 
GuiClose:
	ExitApp
return 
I want to make "MyEdit3" the translator language
And "MyEdit4" is the translated language

Clipboard := GoogleTranslate(Clipboard, "MyEdit3", "MyEdit4")

From "MyEdit3" to "MyEdit4"
User avatar
boiler
Posts: 16977
Joined: 21 Dec 2014, 02:44

Re: Help with translation script

04 May 2021, 15:41

The languages you put in "From" and "To" need to be their abbreviations as Google understands them. Then the way I implemented it was to put the words to be translated in the first box and click "Translate" and the result in is put in the second box. You don't put quotes around the variable names in the function call, by the way.

Code: Select all

SetKeyDelay, -1, 0
SetDefaultMouseSpeed, 0
Gui -Resize -
Gui  +LastFound
height := A_ScreenHeight-485
Gui, Add, Text, x15, ....
Gui, Add, Edit, r1 vMyEdit w130,
Gui, Add, Text, x15, ...
Gui, Add, Edit, r1 vMyEdit2 w130,
Gui, Add, Text, x30, From
Gui, Add, Edit, r1 vMyEdit3 w130,
Gui, Add, Text, x30, To
Gui, Add, Edit, r1 vMyEdit4 w130,
Gui, Add, Button, x30 w130, Translate
Gui, Show, x450 y%height%
CoordMode, Mouse screen
SetTimer, Check, 20
return

ButtonTranslate:
	Gui, Submit, NoHide
	GuiControl,, MyEdit2, % GoogleTranslate(MyEdit, MyEdit3, MyEdit4)
return

Check:
MouseGetPos,xx,yy
Tooltip %xx%`,%yy%
return
GoogleTranslate(str, from := "auto", to := "en")  {
   static JS := CreateScriptObj(), _ := JS.( GetJScript() ) := JS.("delete ActiveXObject; delete GetObject;")
   
   json := SendRequest(JS, str, to, from, proxy := "")
   oJSON := JS.("(" . json . ")")

   if !IsObject(oJSON[1])  {
      Loop % oJSON[0].length
         trans .= oJSON[0][A_Index - 1][0]
   }
   else  {
      MainTransText := oJSON[0][0][0]
      Loop % oJSON[1].length  {
         trans .= "`n+"
         obj := oJSON[1][A_Index-1][1]
         Loop % obj.length  {
            txt := obj[A_Index - 1]
            trans .= (MainTransText = txt ? "" : "`n" txt)
         }
      }
   }
   if !IsObject(oJSON[1])
      MainTransText := trans := Trim(trans, ",+`n ")
   else
      trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")

   from := oJSON[2]
   trans := Trim(trans, ",+`n ")
   Return trans
}

SendRequest(JS, str, tl, sl, proxy) {
   static http
   ComObjError(false)
   if !http
   {
      http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
      ( proxy && http.SetProxy(2, proxy) )
      http.open( "get", "https://translate.google.com", 1 )
      http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
      http.send()
      http.WaitForResponse(-1)
   }
   http.open( "POST", "https://translate.google.com/translate_a/single?client=webapp&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=0&ssel=0&tsel=0&pc=1&kc=1"
      . "&tk=" . JS.("tk").(str), 1 )

   http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
   http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
   http.send("q=" . URIEncode(str))
   http.WaitForResponse(-1)
   Return http.responsetext
}

URIEncode(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
}

CreateScriptObj() {
   static doc
   doc := ComObjCreate("htmlfile")
   doc.write("<meta http-equiv='X-UA-Compatible' content='IE=9'>")
   Return ObjBindMethod(doc.parentWindow, "eval")
}
;=============================The Script=======================


F1::
gui,submit,nohide  ;updates gui variables with information from gui

coords1 := StrSplit(myedit,","," ") ;split text string
coords2 := StrSplit(myedit2,","," ")
cx1 := coords1[1], cy1 := coords1[2]
cx2 := coords2[1], cy2 := coords2[2]

mousemove,%cx1%,%cy1%
	ClipSave := ClipboardAll
	Clipboard := ""
	Send, ^{Click}
	ClipWait, 1
	if ErrorLevel
		return
	Clipboard := GoogleTranslate(Clipboard, "ar", "en")
click,left,%cx2%,%cy2%
	Send, %Clipboard% {Enter}
	Clipboard := ClipSave
	return 
GuiClose:
	ExitApp
return
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

Re: Help with translation script

04 May 2021, 16:38

boiler wrote:
04 May 2021, 15:41
The languages you put in "From" and "To" need to be their abbreviations as Google understands them. Then the way I implemented it was to put the words to be translated in the first box and click "Translate" and the result in is put in the second box. You don't put quotes around the variable names in the function call, by the way.

Code: Select all

SetKeyDelay, -1, 0
SetDefaultMouseSpeed, 0
Gui -Resize -
Gui  +LastFound
height := A_ScreenHeight-485
Gui, Add, Text, x15, ....
Gui, Add, Edit, r1 vMyEdit w130,
Gui, Add, Text, x15, ...
Gui, Add, Edit, r1 vMyEdit2 w130,
Gui, Add, Text, x30, From
Gui, Add, Edit, r1 vMyEdit3 w130,
Gui, Add, Text, x30, To
Gui, Add, Edit, r1 vMyEdit4 w130,
Gui, Add, Button, x30 w130, Translate
Gui, Show, x450 y%height%
CoordMode, Mouse screen
SetTimer, Check, 20
return

ButtonTranslate:
	Gui, Submit, NoHide
	GuiControl,, MyEdit2, % GoogleTranslate(MyEdit, MyEdit3, MyEdit4)
return

Check:
MouseGetPos,xx,yy
Tooltip %xx%`,%yy%
return
GoogleTranslate(str, from := "auto", to := "en")  {
   static JS := CreateScriptObj(), _ := JS.( GetJScript() ) := JS.("delete ActiveXObject; delete GetObject;")
   
   json := SendRequest(JS, str, to, from, proxy := "")
   oJSON := JS.("(" . json . ")")

   if !IsObject(oJSON[1])  {
      Loop % oJSON[0].length
         trans .= oJSON[0][A_Index - 1][0]
   }
   else  {
      MainTransText := oJSON[0][0][0]
      Loop % oJSON[1].length  {
         trans .= "`n+"
         obj := oJSON[1][A_Index-1][1]
         Loop % obj.length  {
            txt := obj[A_Index - 1]
            trans .= (MainTransText = txt ? "" : "`n" txt)
         }
      }
   }
   if !IsObject(oJSON[1])
      MainTransText := trans := Trim(trans, ",+`n ")
   else
      trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")

   from := oJSON[2]
   trans := Trim(trans, ",+`n ")
   Return trans
}

SendRequest(JS, str, tl, sl, proxy) {
   static http
   ComObjError(false)
   if !http
   {
      http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
      ( proxy && http.SetProxy(2, proxy) )
      http.open( "get", "https://translate.google.com", 1 )
      http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
      http.send()
      http.WaitForResponse(-1)
   }
   http.open( "POST", "https://translate.google.com/translate_a/single?client=webapp&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=0&ssel=0&tsel=0&pc=1&kc=1"
      . "&tk=" . JS.("tk").(str), 1 )

   http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
   http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
   http.send("q=" . URIEncode(str))
   http.WaitForResponse(-1)
   Return http.responsetext
}

URIEncode(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
}

CreateScriptObj() {
   static doc
   doc := ComObjCreate("htmlfile")
   doc.write("<meta http-equiv='X-UA-Compatible' content='IE=9'>")
   Return ObjBindMethod(doc.parentWindow, "eval")
}
;=============================The Script=======================


F1::
gui,submit,nohide  ;updates gui variables with information from gui

coords1 := StrSplit(myedit,","," ") ;split text string
coords2 := StrSplit(myedit2,","," ")
cx1 := coords1[1], cy1 := coords1[2]
cx2 := coords2[1], cy2 := coords2[2]

mousemove,%cx1%,%cy1%
	ClipSave := ClipboardAll
	Clipboard := ""
	Send, ^{Click}
	ClipWait, 1
	if ErrorLevel
		return
	Clipboard := GoogleTranslate(Clipboard, "ar", "en")
click,left,%cx2%,%cy2%
	Send, %Clipboard% {Enter}
	Clipboard := ClipSave
	return 
GuiClose:
	ExitApp
return
I mean when I put in "MyEdit3" en and "MyEdit4" es
it trans from english to spanish
User avatar
boiler
Posts: 16977
Joined: 21 Dec 2014, 02:44

Re: Help with translation script

04 May 2021, 16:41

Hema Elkady wrote: I mean when I put in "MyEdit3" en and "MyEdit4" es
it trans from english to spanish
That's exactly what it does. Did you try it? Put "en" in MyEdit3 and "es" in MyEdit4, and "How are you?" in MyEdit1, then press the Translate button. The result in MyEdit2 is "¿Cómo estás?+¿Cómo está usted?¿Cómo está?¿Qué tal?" when I do it.
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

Re: Help with translation script  Topic is solved

04 May 2021, 16:47

boiler wrote:
04 May 2021, 16:41
Hema Elkady wrote: I mean when I put in "MyEdit3" en and "MyEdit4" es
it trans from english to spanish
That's exactly what it does. Did you try it? Put "en" in MyEdit3 and "es" in MyEdit4, and "How are you?" in MyEdit1, then press the Translate button. The result in MyEdit2 is "¿Cómo estás?+¿Cómo está usted?¿Cómo está?¿Qué tal?" when I do it.
it works my freind
Thanks There is a little bit of mod I will try on
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

Re: Help with translation script

04 May 2021, 17:15

boiler wrote:
04 May 2021, 15:41
The languages you put in "From" and "To" need to be their abbreviations as Google understands them. Then the way I implemented it was to put the words to be translated in the first box and click "Translate" and the result in is put in the second box. You don't put quotes around the variable names in the function call, by the way.

Code: Select all

SetKeyDelay, -1, 0
SetDefaultMouseSpeed, 0
Gui -Resize -
Gui  +LastFound
height := A_ScreenHeight-485
Gui, Add, Text, x15, ....
Gui, Add, Edit, r1 vMyEdit w130,
Gui, Add, Text, x15, ...
Gui, Add, Edit, r1 vMyEdit2 w130,
Gui, Add, Text, x30, From
Gui, Add, Edit, r1 vMyEdit3 w130,
Gui, Add, Text, x30, To
Gui, Add, Edit, r1 vMyEdit4 w130,
Gui, Add, Button, x30 w130, Translate
Gui, Show, x450 y%height%
CoordMode, Mouse screen
SetTimer, Check, 20
return

ButtonTranslate:
	Gui, Submit, NoHide
	GuiControl,, MyEdit2, % GoogleTranslate(MyEdit, MyEdit3, MyEdit4)
return

Check:
MouseGetPos,xx,yy
Tooltip %xx%`,%yy%
return
GoogleTranslate(str, from := "auto", to := "en")  {
   static JS := CreateScriptObj(), _ := JS.( GetJScript() ) := JS.("delete ActiveXObject; delete GetObject;")
   
   json := SendRequest(JS, str, to, from, proxy := "")
   oJSON := JS.("(" . json . ")")

   if !IsObject(oJSON[1])  {
      Loop % oJSON[0].length
         trans .= oJSON[0][A_Index - 1][0]
   }
   else  {
      MainTransText := oJSON[0][0][0]
      Loop % oJSON[1].length  {
         trans .= "`n+"
         obj := oJSON[1][A_Index-1][1]
         Loop % obj.length  {
            txt := obj[A_Index - 1]
            trans .= (MainTransText = txt ? "" : "`n" txt)
         }
      }
   }
   if !IsObject(oJSON[1])
      MainTransText := trans := Trim(trans, ",+`n ")
   else
      trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")

   from := oJSON[2]
   trans := Trim(trans, ",+`n ")
   Return trans
}

SendRequest(JS, str, tl, sl, proxy) {
   static http
   ComObjError(false)
   if !http
   {
      http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
      ( proxy && http.SetProxy(2, proxy) )
      http.open( "get", "https://translate.google.com", 1 )
      http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
      http.send()
      http.WaitForResponse(-1)
   }
   http.open( "POST", "https://translate.google.com/translate_a/single?client=webapp&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=0&ssel=0&tsel=0&pc=1&kc=1"
      . "&tk=" . JS.("tk").(str), 1 )

   http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
   http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
   http.send("q=" . URIEncode(str))
   http.WaitForResponse(-1)
   Return http.responsetext
}

URIEncode(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
}

CreateScriptObj() {
   static doc
   doc := ComObjCreate("htmlfile")
   doc.write("<meta http-equiv='X-UA-Compatible' content='IE=9'>")
   Return ObjBindMethod(doc.parentWindow, "eval")
}
;=============================The Script=======================


F1::
gui,submit,nohide  ;updates gui variables with information from gui

coords1 := StrSplit(myedit,","," ") ;split text string
coords2 := StrSplit(myedit2,","," ")
cx1 := coords1[1], cy1 := coords1[2]
cx2 := coords2[1], cy2 := coords2[2]

mousemove,%cx1%,%cy1%
	ClipSave := ClipboardAll
	Clipboard := ""
	Send, ^{Click}
	ClipWait, 1
	if ErrorLevel
		return
	Clipboard := GoogleTranslate(Clipboard, "ar", "en")
click,left,%cx2%,%cy2%
	Send, %Clipboard% {Enter}
	Clipboard := ClipSave
	return 
GuiClose:
	ExitApp
return
In the original code "MyEdit1" I put my coordinates in it so that the mouse can go to it to copy some text
"MyEdit2" I put my coordinate in a place that the mouse clicks on and sends the translation
In the original code "MyEdit1" I put my coordinates in it so that the mouse can go to it to copy some text
"MyEdit2" I put my coordinate in a place that the mouse clicks on and sends the translation
User avatar
boiler
Posts: 16977
Joined: 21 Dec 2014, 02:44

Re: Help with translation script

04 May 2021, 17:21

You don't need to use coordinates to copy text from the edit fields. When you use Gui, Submit (with or without , NoHide), it puts the text that was entered in the variables MyEdit1, MyEdit2, etc. You can also use GuiControlGet to get the contents of a particular control.
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

Re: Help with translation script

05 May 2021, 11:32

boiler wrote:
04 May 2021, 17:21
You don't need to use coordinates to copy text from the edit fields. When you use Gui, Submit (with or without , NoHide), it puts the text that was entered in the variables MyEdit1, MyEdit2, etc. You can also use GuiControlGet to get the contents of a particular control.
My job is to judge that
User avatar
boiler
Posts: 16977
Joined: 21 Dec 2014, 02:44

Re: Help with translation script

05 May 2021, 11:54

Hema Elkady wrote: My job is to judge that
And I thought the reason you were posting about it was to get tips on how to do things easier and more efficiently, but you can do whatever you want, of course. I have no idea why you would purposely use such an unnecessary and overly complicated approach, but I don’t need to know. I’ll make sure not to question your judgment in the future. Good luck.
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

Re: Help with translation script

05 May 2021, 12:14

boiler wrote:
05 May 2021, 11:54
Hema Elkady wrote: My job is to judge that
And I thought the reason you were posting about it was to get tips on how to do things easier and more efficiently, but you can do whatever you want, of course. I have no idea why you would purposely use such an unnecessary and overly complicated approach, but I don’t need to know. I’ll make sure not to question your judgment in the future.
Thank you very much

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 318 guests