Activate hotkeys in specific web page

Get help with using AutoHotkey and its commands and hotkeys
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Activate hotkeys in specific web page

15 Jan 2020, 02:20

Hi Everyone,

I'm need help with short script.
when specific web page that starts with "www.notion.so" is open in foreground, activate hotkeys.

something like:

Code: Select all

 #ifWinActive notion

   !a::
   MsgBox, Notion is opened
   Return

 #ifWinActive
Thanks in advance
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Activate hotkeys in specific web page

15 Jan 2020, 02:56

Code: Select all

SetTitleMatchMode 2  ; 2: A window's title can contain WinTitle anywhere inside it to be a match. 
#IfWinActive notion  ; if 'Notion' in the title
!a::
    msgbox Notion is Active
    return
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: Activate hotkeys in specific web page

15 Jan 2020, 03:30

telanx Thanks for your Reply
I tried your script by unfortunately it doesn't do nothing as mine
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Activate hotkeys in specific web page

15 Jan 2020, 04:10

Don't try to get the browser address bar variable, you should get the title of the tab.
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: Activate hotkeys in specific web page

15 Jan 2020, 05:18

I didn't understood what you meaning. could you please share a example script
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Activate hotkeys in specific web page

15 Jan 2020, 06:25

This script will work when your window (tab) title contains 'notion'.
For example, open Google, search for 'notion', and then press the shortcut key (alt-a) to try it.
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: Activate hotkeys in specific web page

15 Jan 2020, 08:05

thanks for clearout your thought. i tried it lot of time but it didn't worked before so neither now.
and the strange thing is that I done simple script that I can selectively trigger youtube, google, Facebook etc... with absolutely same syntex.

Code: Select all


#IfWinActive, ahk_exe chrome.exe

  #if WinActive("YouTube")
  !a::
      msgbox YouTube is Active
      return
  #ifWinActive

  #ifWinActive Facebook
    !a::
        msgbox Facebook is Active
        return
    #ifWinActive

  #if WinActive("Google") AND !WinActive("YouTube") AND !WinActive("Facebook")
  !a::
      msgbox Google is Active
      return
  #ifWinActive

  
#IfWinActive  
  
but in case of notion (https://www.notion.so/) such method absolutely doesn't work for some reason.
any idea?
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Activate hotkeys in specific web page

15 Jan 2020, 08:29

This code works fine for me, talk about browser, operating system, ahk version you use.

Code: Select all

SetTitleMatchMode 2  ; 2: A window's title can contain WinTitle anywhere inside it to be a match. 
#IfWinActive YouTube  ; if 'Notion' in the title
!a::
    msgbox YouTube is Active
    return
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: Activate hotkeys in specific web page

15 Jan 2020, 10:08

telanx i absolutely agree with you, Youtube, Facebook, Google and any other webpage I tried works well for me. all beside Notion.
Maybe its some how related to the fact that its web app or any other reason
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Activate hotkeys in specific web page

15 Jan 2020, 10:39

Tested this no problem, there were previous syntax problems. The title is case sensitive.

Code: Select all

SetTitleMatchMode 2  ; 2: A window's title can contain WinTitle anywhere inside it to be a match. 

!a::
    If WinActive("Notion")  ; if 'Notion' in the title
        msgbox Notion is Active
    return
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: Activate hotkeys in specific web page

15 Jan 2020, 11:13

the same as before.

Code: Select all

    #IfWinActive Notion 
    !h::
        msgbox Notion is Active
    return
but I notice something interesting while reloading before page was fully loaded the key get triggered and working correctly until the page was fully loaded.
which means syntax "Notion" is right but something \ process when notion was fully loaded blocks the key to get triggered (i tried different key combination).
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Activate hotkeys in specific web page

15 Jan 2020, 11:23

This is keyword list version. same hotkey.

Code: Select all

; keyword list, warning: Case Sensitive
Keyword := "YouTube,Notion,Instagram"

!a::
    WinGetTitle, Title, A   ;Get Window Title
    loop, Parse, Keyword, `,    ;Keyword slicing
    {
        while inStr(Title, A_LoopField) {   ;while keyword in title
            switch A_LoopField {    ;which keyword
                case "Notion":
                    msgbox Notion
                case "YouTube":
                    msgbox YouTube
                case "Instagram":
                    msgbox ins
                return
            }
            return
        }
    }
    return
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Activate hotkeys in specific web page

15 Jan 2020, 11:31

This function is title based, so you have to wait for the browser to get the full title to work well.
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: Activate hotkeys in specific web page

15 Jan 2020, 12:01

as before every site get triggered with relative title beside notion.

thank you very much for willing to help

Return to “Ask For Help”

Who is online

Users browsing this forum: braunbaer, effel, GamesOfFreak, kintar0e, Lorien, mikeyww and 57 guests