Search in google, please help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Search in google, please help

21 May 2017, 11:44

hi guys
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
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Search in google, please help

21 May 2017, 13:18

thank you very much,
but gave me any sample please
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Search in google, please help

21 May 2017, 15:17

hi guys

I have tried with these examples but failed..
please help

Code: Select all

; Example #1: Maximize the active window and report its unique ID:
WinGet, active_id, ID, A
WinMaximize, ahk_id %active_id%
MsgBox, The active window's ID is "%active_id%".

; Example #2: This will visit all windows on the entire system and display info about each of them:
WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinActivate, ahk_id %this_id%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
    IfMsgBox, NO, break
}

; Example #3: Extract the individual control names from a ControlList:
WinGet, ActiveControlList, ControlList, A
Loop, Parse, ActiveControlList, `n
{
    MsgBox, 4,, Control #%a_index% is "%A_LoopField%". Continue?
    IfMsgBox, No
        break
}

; Example #4: Display in real time the active window's control list:
#Persistent
SetTimer, WatchActiveWindow, 200
return
WatchActiveWindow:
WinGet, ControlList, ControlList, A
ToolTip, %ControlList%
return
Guest

Re: Search in google, please help

22 May 2017, 05:21

Code: Select all

!1::    ; <-- Google Search Using Highlighted Text
WinGet, active_id, ID, A ; Get active window ID
; your code
; your code
WinActivate, ahk_id %active_id% ; Restore active window ID
active_id:="" ; clear variable
Return
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Search in google, please help

22 May 2017, 14:56

thanks, Guest
but i don't understand
because i can't use the variable
all of i need now that is: how the code remember the last window came from it
please sample example:

Code: Select all

!q::
ifWinExist, ahk_class Notepad ; ----------- Notepad window
WinActivate, ahk_class Notepad
Sleep, 200
send, abcd
Sleep, 200
; ?????
; how this macro back to this window: 
; window Title. Class and Process:
;learn - WordPad
;ahk_class WordPadClass
;ahk_exe wordpad.exe

;by Using the function: WinGet, active_id, ID, A or any another way by variable.
please help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 392 guests