Page 1 of 1

Enable hotkey if specific Browser-URL is accessed

Posted: 18 Aug 2018, 08:52
by Banayat
Hi, I want to replace a mouse key originally set to webbrowsing backwards with my own function:

- enable hotkey if Chrome Browser is active and URL "www.google ..." has been typed into address bar.

I got the following code from TLM (Administrator) which I couldn't get to work though. See link below. The problem is that "IfWinActive" seems not to be able to recognize the Chrome Browser at all. What need to be done to make this one work?

https://autohotkey.com/board/topic/8778 ... dow-title/

Code: Select all

GroupAdd, MyGroup, ahk_class Chrome_WidgetWin_1 && GetWinText("www.google")

GetWinText(t) {
    WinGetText, wText, A
    Return RegExMatch( wText, "s)" t )

#IfWinActive ahk_group MyGroup
$XButton1::
   if A_PriorHotkey <> $XButton1
   {
      KeyWait, XButton1
      return
   }
   if A_TimeSincePriorHotkey > 400
   {
      KeyWait, XButton1
      return
   }
   Msplit()
Return
#IfWinActive

Msplit()
{
Tooltip Yes!
}

Re: Enable hotkey if specific Browser-URL is accessed

Posted: 19 Aug 2018, 15:50
by BriHecato
Shouldn't the GetWinText function be before GroupAdd ?

Re: Enable hotkey if specific Browser-URL is accessed

Posted: 20 Aug 2018, 10:49
by Banayat
Maybe. I guess it does not interfere with other functions in the first place. No success on putting GetWinText to the end of script.

Re: Enable hotkey if specific Browser-URL is accessed

Posted: 20 Aug 2018, 16:53
by jackdunning
I don't think that you can place a function in the GroupAdd command unless you use a forced expression operator. Maybe try this and forget the function:

GroupAdd, MyGroup, Google - Google Chrome

Re: Enable hotkey if specific Browser-URL is accessed

Posted: 20 Aug 2018, 17:15
by jackdunning
Here's a test script:

Code: Select all

GroupAdd, MyGroup, Google - Google Chrome

#IfWinActive ahk_group MyGroup
^#g::
   MsgBox, It's Google!
Return

#IfWinActive
^#g::
  MsgBox It's not Google!
Return

Re: Enable hotkey if specific Browser-URL is accessed

Posted: 20 Aug 2018, 17:19
by jackdunning
Or, if you only need it for Google:

Code: Select all

#IfWinActive Google - Google Chrome
^#g::
   MsgBox, It's Google!
Return

#IfWinActive

^#g::
  MsgBox It's not Google!
Return

Re: Enable hotkey if specific Browser-URL is accessed

Posted: 23 Aug 2018, 20:05
by Banayat
The Reason why I am using GroupAdd is that it's more than one window belonging to "#IfWinActive". Whenever I add more to it it does not work. Any Workaround?