Google-chrome – Autohotkeys cannot recognize Google Chrome Windows. What can I do

autohotkeygoogle-chromeshortcuts

I am creating a hotkey in autohotkeys, to activate Google Chrome, or move between all Chrome windows.

The HotKey is Win + H (h meaning http).

If the user presses Win + Shift + H it opens a new chrome window

If the user presses Win + H twice, it moves between all chrome windows:

Update: See the full script in the bottom. Thank you everyone:

The problem is that AutoHotKeys cannot find the class of chrome, so it's always open new window:

This function always returns false:
If WinExist ahk_class Chrome_WidgetWin_1

Please advise.

the script file:

#h::
SetTitleMatchMode, 2
If WinExist ahk_class Chrome_WidgetWin_1
{
ifWinActive
WinActivatebottom ,Chrome_WidgetWin_1
else
WinActivate 
return
}
run chrome.exe

I found the bug.

There is a bug with ifWinExist function in this version of AutoHotkeys, and Google Chrome.
The user can use;

WinActivate ahk_class Chrome_WidgetWin_1

but cannot use:

If WinExist ahk_class Chrome_WidgetWin_1

It is always false!

Hope this question&answer help to someone (I cannot write answer, because I have only 1 reputation point)

Update:
This is ahk source code, for
Win + n Open Notepad or switching between open notepads.

+ Shift + n Open new notepad.

Win + c Open cmd.exe or switching between console windows.

Win + Shift + c Open new console.

Win + h Open Google Chrome or switching between Chrome windows
+ Shift + h Open new browser.

SetTitleMatchMode, 2


;********command line
#c::
IfWinExist ,cmd.exe
{
ifWinActive
WinActivatebottom ,cmd.exe
else
WinActivate
return
}
#+c::
run cmd.exe
return

;******************Chrome
#h::
IfWinExist ,Chrome
    {
    ifWinActive
        {
        WinActivatebottom ,Chrome
    }
    else
    {
        WinActivate
    }
    return
}

#+h::
run "chrome"
return 
;**************Notepad
#n::
IfWinExist ,Notepad
    {
    ifWinActive
        {
        WinActivatebottom ,Notepad
    }
    else
    {
        WinActivate
    }
    return
}

#+n::
run "notepad"
return

Best Answer

  • 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