The following code for Search in google, I have two question, and I hope you will help me please
1- this code Each time I select the text and press Hotkey
Google opens a new tab.
my question is: Is it possible the code use same google tab each time.
----------------------
2- The following code for close the Google tab and activates:
- Word window by "w" hotkey
or
- Notepad window by "n" hotkey
or
- Excel window by "e" hotkey
my question is: How do I make it remember the window it came from, Then back to the same window
Any help will be appreciated
thanks in advance
Code: Select all
; Google Search
; Fanatic Guru
; 2014 05 01
; Version: 1.0
;
; Google Search of Highlighted Text
;
; INITIALIZATION - ENVIROMENT
;{-----------------------------------------------
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force ; Ensures that only the last executed instance of script is running
;}
; AUTO-EXECUTE
;{-----------------------------------------------
;
RegRead, ProgID, HKEY_CURRENT_USER, Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice, Progid
Browser := "iexplore.exe"
if (ProgID = "ChromeHTML")
Browser := "chrome.exe"
if (ProgID = "FirefoxURL")
Browser := "firefox.exe"
;
;}-----------------------------------------------
; END OF AUTO-EXECUTE
; HOTKEYS
;{-----------------------------------------------
;
!1:: ; <-- Google Search Using Highlighted Text
Save_Clipboard := ClipboardAll
Clipboard := ""
Send ^{VK43}
ClipWait, 2
if !ErrorLevel
{
Query := Clipboard
}
else { ; no text selected - bring up popup
InputBox, Query, Google Search, , , 200, 100
}
Gosub Search
Clipboard := Save_Clipboard
Save_Clipboard := ""
return
;}
; SUBROUTINES
;{-----------------------------------------------
;
Search:
StringReplace, Query, Query, `r`n, %A_Space%, All
StringReplace, Query, Query, %A_Space%, `%20, All
StringReplace, Query, Query, #, `%23, All
Query := Trim(Query)
if (Browser = "iexplore.exe")
{
Found_IE := false
For wb in ComObjCreate("Shell.Application").Windows
If InStr(wb.FullName, "iexplore.exe")
{
Found_IE := true
break
}
if Found_IE
wb.Navigate("http://google.com/search?hl=en&q=" Query, 2048)
else
{
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate("http://google.com/search?hl=en&q=" Query)
}
}
else
Run, %browser% http://www.google.com/search?hl=en&q=%Query%
return
;}
#IfWinActive ahk_class Chrome_WidgetWin_1
w::
sleep, 200
send ^w
sleep, 500
ifWinExist, ahk_class OpusApp ; -----------MS word window
WinActivate, ahk_class OpusApp
return
#IfWinActive ahk_class Chrome_WidgetWin_1
n::
sleep, 200
send ^w
sleep, 500
ifWinExist, ahk_class Notepad ; ----------- Notepad window
WinActivate, ahk_class Notepad
return
#IfWinActive ahk_class Chrome_WidgetWin_1
e::
sleep, 200
send ^w
sleep, 500
ifWinExist, ahk_class XLMAIN ; ----------- Excel window
WinActivate, ahk_class XLMAIN
return