^+i::
if WinExist("ahk_class Chrome_WindowImpl_0")
{
WinActivate
ControlFocus, Chrome_AutocompleteEditView1
}
else
Run "C:\Users\vleeshue\AppData\Local\Google\Chrome\Application\chrome.exe"
return
Should do the trick
("Chrome_AutocompleteEditView1" is the name of the omnibar control, so you could add Send ^a
to select all)
Note: To get the ahk_class
for your version of Chrome, e.g., ahk_class Chrome_WindowImp1-0
, use the AU3_Spy.exe
inside the autohotkey directory. This will allow you to find the correct ahk class for your chrome browser if the example one doesn't work.
Update: I can't reproduce, maybe it will be better with another control...
To have a list of a window controls I use this code:
#Persistent
SetTimer, WatchCursor, 100
return
WatchCursor:
MouseGetPos, , , id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
WinGet, ControlList, ControlList, A
ToolTip, Under Cursor:`nahk_id: %id%`nahk_class: %class%`nTitle:%title%`nControl: %control%`n`nWindow Control List:`n%ControlList%
return
So the controls of my google chrome 4.0.249.78 beta (36714) are:
- ViewsTextfieldEdit1
- Chrome_RenderWidgetHostWND1
- Chrome_AutocompleteEditView1
- Chrome_WindowImpl_01
- Chrome_WindowImpl_02
I use the name only (since Google once changed the class name). Here is an expample in AHK_L that I use.
SetTitleMatchMode, 2
#ifWinActive, Chrome
NumpadIns::Send, {Click}
NumpadRight::Send, ^{PgDn} ; Right arrow = activate next Tab
NumpadLeft::Send, ^{PgUp} ; Left arrow = activate previous tab
#ifWinActive
Best Answer
Most likely WInactivate does not work because you need to add
SetTitleMatchMode, 2
at the top of your script. To test if WinActivate really works use this:If you do NOT see the OK message, your Winactivate still waits for the correct title. Once you are sure this works, you can reduce is back to: