0
votes

I have some simple ahk code that works great when I am using Firefox, but I cannot construct an equivalent for Chrome. The idea is that the functional part of the code should only "apply" when Chrome is open and the active (focused) window.

Here is what works for Firefox:

;MUST BE LAST PART OF SCRIPT!!
SetTitleMatchMode, 2
`#IfWinActive,  - Mozilla Firefox
;Above "- Mozilla Firefox" substring appears in all Firefox windows
{code to be applicable goes here}
`#ifwinactive

The problem is that Chrome has no Window Title, so I cannot construct the `#IfWinActive line.

Does anyone have an idea how this can be done for Chrome? And perhaps even so that the script could detect EITHER Firefox OR Chrome being active and focused?

2

2 Answers

0
votes

Try to use your AHK Windows Spy. You will find the following class data:

Autohotkey - How to restrict commands to when Chrome open - Stack Overflow - Google Chrome
ahk_class Chrome_WidgetWin_1
ahk_exe chrome.exe

Part of every window title IS "Google Chrome" at the end, but you should try to use the ahk_class Chrome_WidgetWin_1

Remember that #IfWinActive ONLY works with things like hotkeys. You can't just put code there and expect the code to run as soon as you have activated Chrome. If that is what you want, you will have to use a check loop or OnMessage.

0
votes

jcarerra, If you want to use the same hotkeys, performing the same tasks in two or more different applications, you can group the applications in the following way:

GroupAdd MyBrowsers, ahk_class MozillaWindowClass
GroupAdd MyBrowsers, ahk_class Chrome_WidgetWin_1
#IfWinActive ahk_group MyBrowsers
    Your Hotkey code here.....
#IfWinActive

In this example, I used the Application class ID's from Chrome and FireFox and combined them into a group named MyBrowsers. Then in the #IfWinActive function, you refer to the groupname MyBrowsers.

Hope this helps