lsakizada Posted June 9, 2009 Posted June 9, 2009 Hi, This little script supposed to launch a browser and search in google automaticaly with current selected keyword string.basically, when you select/highlight string on any application, and push the 'alt' keyboard and middle mouse button, it popup the google search.My problem that it is working for English characters but not with other languages.For example:Open this website http://www.google.co.il/ , select Hebrew string, push the alt and middle mouse button simultanously.the problem is taht it wont pass the Hebrew characters correctly.if you try it with English string then it will work.expandcollapse popup#NoTrayIcon #include <Misc.au3> Global $KeyA="12" , $KeyB="04" Global $new_clip = "" Global $hDll = DllOpen("user32.dll") If $hDll = "-1" Then Exit EndIf While 1 Sleep(100) If _IsPressed($KeyA, $hDll) And _IsPressed($KeyB, $hDll) Then ;_GetText() ControlSend(WinGetHandle(''), '', '', '^c') $new_clip = ClipGet() _LaunchBrowser("http://www.google.co.il/search?q=" & _URLEncode(StringStripCR($new_clip))) EndIf WEnd DllClose($hDll) Func _URLEncode($sURL) Local $aEncodable[13] = ['"', "'", "<", ">", "\", "^", "[", "]", "`", "+", "$", ",", "#"] ;encode % first because encoding will add more % to the url Local $sTemp = StringReplace($sURL, "%", "%25") ;encode non-printable and space For $x = 0 To 32 $sTemp = StringReplace($sTemp, Chr($x), "%" & Hex($x, 2)) Next ;encode "unsafe" For $x = 0 To UBound($aEncodable) - 1 $sTemp = StringReplace($sTemp, $aEncodable[$x], "%" & Hex(Asc($aEncodable[$x]), 2)) Next ;encode upper ascii and {}|~_ For $x = 123 To 255 $sTemp = StringReplace($sTemp, Chr($x), "%" & Hex($x, 2)) Next Return $sTemp EndFunc ;==>_URLEncode Func _LaunchBrowser($URL) ShellExecute($URL) EndFunc ;==>_LaunchBrowser Be Green Now or Never (BGNN)!
KenNichols Posted June 9, 2009 Posted June 9, 2009 Hi, This little script supposed to launch a browser and search in google automatically with current selected keyword string. basically, when you select/highlight string on any application, and push the 'alt' keyboard and middle mouse button, it popup the google search. My problem that it is working for English characters but not with other languages. For example: Open this website http://www.google.co.il/ , select Hebrew string, push the alt and middle mouse button simultaneously. the problem is that it wont pass the Hebrew characters correctly. if you try it with English string then it will work. I believe your problem lies in the "Func _URLEncode" @ Hex(Asc($aEncodable[$x]), 2) I believe it doesn't understand the Hebrew characters. Good Luck, I hope this helps! [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
lsakizada Posted June 10, 2009 Author Posted June 10, 2009 I believe your problem lies in the "Func _URLEncode" @ Hex(Asc($aEncodable[$x]), 2) I believe it doesn't understand the Hebrew characters. Good Luck, I hope this helps! I checked it and there is nothing to do with the _URLEncode function. I see that the problem is with the Clipget() function. I simplified the code: #NoTrayIcon #include <Misc.au3> Global $KeyA="12" , $KeyB="04"; 'alt' and mid mouse button Global $new_clip = "" Global $hDll = DllOpen("user32.dll") If $hDll = "-1" Then Exit EndIf While 1 Sleep(100) If _IsPressed($KeyA, $hDll) And _IsPressed($KeyB, $hDll) Then ControlSend(WinGetHandle(''), '', '', '^c') $new_clip = ClipGet() _LaunchBrowser("http://www.google.co.il/search?q=" & StringStripCR($new_clip)) EndIf WEnd DllClose($hDll) Func _LaunchBrowser($URL) ShellExecute($URL) EndFunc ;==>_LaunchBrowser Be Green Now or Never (BGNN)!
KenNichols Posted June 10, 2009 Posted June 10, 2009 Try this! expandcollapse popup#NoTrayIcon #include <Misc.au3> #include <IE.au3> Global $KeyA="12" , $KeyB="04" Global $new_clip = "" Global $hDll = DllOpen("user32.dll") If $hDll = "-1" Then Exit EndIf While 1 Sleep(100) If _IsPressed($KeyA, $hDll) And _IsPressed($KeyB, $hDll) Then ;_GetText() ControlSend(WinGetHandle(''), '', '', '^c') $new_clip = ClipGet() ;_LaunchBrowser("http://www.google.co.il/search?q=" & _URLEncode(StringStripCR($new_clip))) $oIE = _IECreate() _IENavigate($oIE, "http://www.google.co.il") $oForm = _IEFormGetObjByName($oIE, "f") $oQuery = _IEFormElementGetObjByName($oForm, "q") _IEFormElementSetValue($oQuery, $new_clip) _IEFormSubmit($oForm) _IELoadWait($oIE) EndIf WEnd DllClose($hDll) Func _URLEncode($sURL) Local $aEncodable[13] = ['"', "'", "<", ">", "\", "^", "[", "]", "`", "+", "$", ",", "#"] ;encode % first because encoding will add more % to the url Local $sTemp = StringReplace($sURL, "%", "%25") ;encode non-printable and space For $x = 0 To 32 $sTemp = StringReplace($sTemp, Chr($x), "%" & Hex($x, 2)) Next ;encode "unsafe" For $x = 0 To UBound($aEncodable) - 1 $sTemp = StringReplace($sTemp, $aEncodable[$x], "%" & Hex(Asc($aEncodable[$x]), 2)) Next ;encode upper ascii and {}|~_ For $x = 123 To 255 $sTemp = StringReplace($sTemp, Chr($x), "%" & Hex($x, 2)) Next Return $sTemp EndFunc ;==>_URLEncode Func _LaunchBrowser($URL) ShellExecute($URL) EndFunc ;==>_LaunchBrowser [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
lsakizada Posted June 10, 2009 Author Posted June 10, 2009 Hi KenNichols, Your solution actually pass the locale string properly but unfortunately this is not the solution that could fit to my solution. it opened to many IEs. But from your solution I understood that I made a mistake and the GetClip function actually works properly. I understood that it is not working when using the ShellExecute function. I tried with _runDos() and run() but non of them is working well. something in the IE.au3 has method that pass it properly. Meantime I am still working on it because I want to create tool that will be used for many sites not just google. please help. Be Green Now or Never (BGNN)!
ProgAndy Posted June 10, 2009 Posted June 10, 2009 It should work if you use UTF-8 for the special chars expandcollapse popup#NoTrayIcon #include <Misc.au3> Global $KeyA="12" , $KeyB="04"; 'alt' and mid mouse button Global $KeyC = '02' ; 'alt' and right mbutton for exit Global $new_clip = "" Global $hDll = DllOpen("user32.dll") If $hDll = "-1" Then Exit EndIf While 1 Sleep(50) If _IsPressed($KeyA, $hDll) Then If _IsPressed($KeyB, $hDll) Then Send('^c') $new_clip = ClipGet() _LaunchBrowser("http://www.google.com/search?q=" & _URIEncode(StringStripCR($new_clip))) ElseIf _IsPressed($KeyC, $hDll) Then Exit EndIf EndIf WEnd DllClose($hDll) Func _LaunchBrowser($URL) ShellExecute($URL) EndFunc ;==>_LaunchBrowser ; #FUNCTION# ==================================================================================================================== ; Name...........: _URIEncode ; Description ...: Encodes a string to be used in an URI ; Syntax.........: _URIEncode($sData) ; Parameters ....: $sData - String to encode ; Return values .: Encoded String ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: This function uses UTF-8 encoding for special chars ; Related .......: _URIDecode ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"") Local $nChar $sData="" For $i = 1 To $aData[0] ;~ ConsoleWrite($aData[$i] & @CRLF) $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48-57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar,2) EndSwitch Next Return $sData EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
lsakizada Posted June 10, 2009 Author Posted June 10, 2009 It should work if you use UTF-8 for the special chars expandcollapse popup#NoTrayIcon #include <Misc.au3> Global $KeyA="12" , $KeyB="04"; 'alt' and mid mouse button Global $KeyC = '02' ; 'alt' and right mbutton for exit Global $new_clip = "" Global $hDll = DllOpen("user32.dll") If $hDll = "-1" Then Exit EndIf While 1 Sleep(50) If _IsPressed($KeyA, $hDll) Then If _IsPressed($KeyB, $hDll) Then Send('^c') $new_clip = ClipGet() _LaunchBrowser("http://www.google.com/search?q=" & _URIEncode(StringStripCR($new_clip))) ElseIf _IsPressed($KeyC, $hDll) Then Exit EndIf EndIf WEnd DllClose($hDll) Func _LaunchBrowser($URL) ShellExecute($URL) EndFunc ;==>_LaunchBrowser ; #FUNCTION# ==================================================================================================================== ; Name...........: _URIEncode ; Description ...: Encodes a string to be used in an URI ; Syntax.........: _URIEncode($sData) ; Parameters ....: $sData - String to encode ; Return values .: Encoded String ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: This function uses UTF-8 encoding for special chars ; Related .......: _URIDecode ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"") Local $nChar $sData="" For $i = 1 To $aData[0] ;~ ConsoleWrite($aData[$i] & @CRLF) $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48-57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar,2) EndSwitch Next Return $sData EndFunc Thank you! now its working smootly. I have one issue opened with it, how do I verified that only one browser will be opened? I do not want to open a browser on each search... Be Green Now or Never (BGNN)!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now