The Ctrl+Win+a / Ctrl+Win+p are so that I get a fast search into on programming (save me typing in "PowerShell" or "Autohotkey" every time I want to search!).
A problem with the below is that in the browser, I don't know how to detect when a task has finished (by which I mean "has the page fully loaded?") which is why I do the ^l twice.
Is there a way to do something like that? When interacting with Chrome, this would be massively useful so that instead of putting random length "Sleep" statements in, we could have a structured means of waiting until I know the thing has finished loaded before I continue - mostly Chrome responds really fast, fraction of a second usually, but sometimes it can take 3-8 seconds of seemingly doing nothing before it loads a page - obviously, if my approach here is all wrong, I'd appreciate pointer to use better functions that achieve the goal more efficiently! .
Code: Select all
#IfWinActive ahk_exe chrome.exe
^g:: ; Quick search for Google, use this as I set default search engine to DuckDuckGo for anonymity, but sometimes need/want google.com
WinActivate ahk_exe chrome.exe
WinWaitActive ahk_exe chrome.exe ; Activates the last found and open a new tab
Send ^l ; Ctrl-l to activate address bar ; Send ^t would do a 'Ctrl-t' to open a new tab, or Run % "chrome.exe --new-tab" url
Sleep 50
Send ^l ; Ctrl-l to activate address bar (do it a second time just in case)
Sleep 50
SendInput, www{.}google{.}com ; when using more complex urls, replace characters by their SendInput equivalent: url := RegExReplace(url, "#", "{#}")
Sleep 50
SendInput, {Enter} ; Default focus will jump to the Google search entry field so we don't need to do any more than this
Sleep 50
WinActivate ahk_exe chrome.exe
WinWaitActive ahk_exe chrome.exe ; Activates the last found
return
^m:: ; Quick search in Google Maps (the default DuckDuckGo maps are substandard so I need a quick way into them)
Sleep 200
WinActivate ahk_exe chrome.exe
WinWaitActive ahk_exe chrome.exe ; Activates the last found and open a new tab
Send ^l ; Ctrl-l to activate address bar
Sleep 100
; Send ^t ; Ctrl-t to open a new tab
; Sleep 100
Send ^l ; Ctrl-l to activate address bar (do it a second time just in case)
Sleep 50
SendInput, maps{.}google{.}com ; Default focus jumps to Maps search, so don't need to do any more than this.
Sleep 100
SendInput, {Enter}
Sleep 100
return
^#a:: ; AutoHotkey
WinActivate ahk_exe chrome.exe
WinWaitActive ahk_exe chrome.exe
Sleep 50
Send ^l
Sleep 50
Send ^a ; select all to overwrite
SendInput, AutoHotkey{Space}
Sleep 50
return
^#p:: ; PowerShell
WinActivate ahk_exe chrome.exe
WinWaitActive ahk_exe chrome.exe
Sleep 50
Send ^l
Sleep 50
Send ^a ; select all to overwrite
SendInput, PowerShell{Space}
Sleep 50
return
#IfWinActive
; Below might be useful as global searches outside of #IfWinActive.
; Note: do not make 4x char in a row "aaaa", as possibility of activating by accident by leaning on a key. Below are hard to do by accident.
; aaas "Autohotkey Search", ppps "PowerShell Search", etc
:x*:aaas:: ; Quick search for AutoHotkey, opens Chrome, then fills "AutoHotkey " ready to search for something
WinActivate ahk_exe chrome.exe
WinWaitActive ahk_exe chrome.exe
Sleep 50
Send AutoHotkey{Space}
return
:x*:ppps:: ; Quick search for AutoHotkey, opens Chrome, then fills "AutoHotkey " ready to search for something
WinActivate ahk_exe chrome.exe
WinWaitActive ahk_exe chrome.exe
Sleep 50
Send AutoHotkey{Space}
return