How can I use Autohotkey to focus on an existing Google Chrome tab, not a "container" window?
Details
Google Chrome seems to represent each window with a container window handle, which contains one or more tabs. The tabs (at least the current one), has its own window handle. The tab window handles have window titles (which currently all end in " – Google Chrome"), whereas the container window handle itself does not. The following autohotkey code does not work as intended for Google Chrome:
^+i::
if WinExist("ahk_class Chrome_WidgetWin_0")
WinActivate
else
Run "C:\Users\vleeshue\AppData\Local\Google\Chrome\Application\chrome.exe"
return
This binding will focus on a Google Chrome window if it exists or will run Google Chrome. However, it will often target the container window (in Window Spy, the window title is blank). Activating the container window disallows the use of Google Chrome keyboard shortcuts. The inaccessible keyboard shortcuts include the all important ctrl+l to access the omnibar. Since I have not yet found a way to consistently activate the tab window instead of the container window, my workaround is to use the mouse, but I'd prefer to avoid that if possible.
Window Spy Screenshots
Background
Current Google Chrome Version: 5.0.317.2 dev
A common autohotkey binding I use is a keyboard shortcut to focus a specific application if it's already running or to run the application if it isn't running.
For example, I use this for foobar2000
^+m::
If WinExist("foobar2000")
WinActivate
else
Run "C:\Program Files (x86)\foobar2000\foobar2000.exe"
return
Best Answer
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 theAU3_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:
So the controls of my google chrome 4.0.249.78 beta (36714) are: