IfWinActive with Websites

Get help with using AutoHotkey and its commands and hotkeys
Liaxim
Posts: 31
Joined: 09 Jan 2020, 05:14

IfWinActive with Websites

17 Jan 2020, 11:33

Is it possible to look if a website is opened? I tried some IfWinActive things but I found only the browser class... like

Code: Select all

IfWinActive, ahk_exe firefox.exe
would be nice if anyone have an idea
ufunk
Posts: 16
Joined: 17 Jan 2020, 13:45

Re: IfWinActive with Websites

17 Jan 2020, 14:11

Hi,

I am new here, so I am not sure if it helps, but I think something similar about this topic is written here:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=26947
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: IfWinActive with Websites

17 Jan 2020, 20:13

An easy way is to match if a keyword exists in the title and then run the function you need.

Code: Select all

; keyword list, 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
Liaxim
Posts: 31
Joined: 09 Jan 2020, 05:14

Re: IfWinActive with Websites

12 Feb 2020, 14:38

telanx wrote:
17 Jan 2020, 20:13
An easy way is to match if a keyword exists in the title and then run the function you need.

Code: Select all

; keyword list, 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

Thanks for your answer.
I had a problem with the "switch A_LoopField". The program said me all the time that " A_LoopField" is not a recognized action.
I never used this command so did you @telanx or some one else know what is wrong there? Thanks in advance
gregster
Posts: 3849
Joined: 30 Sep 2013, 06:48

Re: IfWinActive with Websites

12 Feb 2020, 15:13

Switch requires AHK v1.1.31+.
Liaxim
Posts: 31
Joined: 09 Jan 2020, 05:14

Re: IfWinActive with Websites

12 Feb 2020, 16:58

gregster wrote:
12 Feb 2020, 15:13
Switch requires AHK v1.1.31+.
Thx I used the Version v1.1.30 ^^ .
I tried it now but It just made nothing as the this code starts.
But now I have no errors anymore
User avatar
boiler
Posts: 3762
Joined: 21 Dec 2014, 02:44

Re: IfWinActive with Websites

12 Feb 2020, 19:58

Liaxim wrote:
12 Feb 2020, 16:58
I tried it now but It just made nothing as the this code starts.
You need to press Alt + A while the browser with the website in question is open to initiate the routine.
Liaxim
Posts: 31
Joined: 09 Jan 2020, 05:14

Re: IfWinActive with Websites

13 Feb 2020, 13:28

boiler wrote:
12 Feb 2020, 19:58
Liaxim wrote:
12 Feb 2020, 16:58
I tried it now but It just made nothing as the this code starts.
You need to press Alt + A while the browser with the website in question is open to initiate the routine.
I know ^^. I tried it but it just not work after the Keyword..
User avatar
boiler
Posts: 3762
Joined: 21 Dec 2014, 02:44

Re: IfWinActive with Websites

13 Feb 2020, 13:50

And you're sure the browser is the active window (and it's open to one of those sites) when you press Alt+A?

If you changed the code at all, even to different keywords, you might want to post your code because slight differences that don't seem important can cause issues when dealing with this stuff.
Liaxim
Posts: 31
Joined: 09 Jan 2020, 05:14

Re: IfWinActive with Websites

13 Feb 2020, 14:28

boiler wrote:
13 Feb 2020, 13:50
And you're sure the browser is the active window (and it's open to one of those sites) when you press Alt+A?

If you changed the code at all, even to different keywords, you might want to post your code because slight differences that don't seem important can cause issues when dealing with this stuff.
Thanks for you answer. Mhh I changed it a little bit but I think it was only the case options and the keyword I think. I try to make a automative login for the Protonmail login. ^^
Here is

Code: Select all

; my encrypted login data
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)

run https mail.protonmail.com /login  Broken Link for safety

; I copied the title from the site but if it´s open it changed to a "Login | ProtonMail" ..
Keyword := "Login - ProtonMail"
!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 "Login - ProtonMail":
                    msgbox,, Login - ProtonMail
                return
            }
            return
        }
    }
    return
MsgBox,,found
Sleep, 5000
Click
send,{tab}
Sleep, 100
send %temporarybenutzer1%
Sleep, 500
send,{tab}
Sleep, 500
send %temporarypasswort1%
send {Enter}
Sleep, 500
Gosub, home
Return
User avatar
boiler
Posts: 3762
Joined: 21 Dec 2014, 02:44

Re: IfWinActive with Websites

13 Feb 2020, 16:25

(answered your PM)
Liaxim
Posts: 31
Joined: 09 Jan 2020, 05:14

Re: IfWinActive with Websites

14 Feb 2020, 11:38

This is the Version which I have right now. I made some Msgboxes to see where my failure is. The Script runs until the "msgbox,,while" and after it appears nothing more happens. Have anyone the answer to this problem?

Code: Select all

Gui, Destroy
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)

run https://mail.protonmail.com/login

Keyword := "Login - ProtonMail"
!a::
MsgBox,,begin
    WinGetTitle, Title, A   ;Get Window Title
    loop, Parse, Keyword, `,    ;Keyword slicing
    {
		MsgBox,,while ; This is the last outputed msgbox..
        while inStr(Title, A_LoopField) 
		{   ;while keyword in title
			MsgBox,,switch
            switch A_LoopField 
			{    ;which keyword
                case "Login - ProtonMail":
				{
					MsgBox,,found
					Sleep, 5000
					Click
					send,{tab}
					Sleep, 100
					send %temporarybenutzer1%
					Sleep, 500
					send,{tab}
					Sleep, 500
					send %temporarypasswort1%
					send {Enter}
					Sleep, 500
					gosub, home
				}
			return
            }
		return
        }
	return
    }
return
User avatar
boiler
Posts: 3762
Joined: 21 Dec 2014, 02:44

Re: IfWinActive with Websites

14 Feb 2020, 13:09

You should MsgBox % Title "`n" A_LoopField in that spot so you can really see what’s happening.
Liaxim
Posts: 31
Joined: 09 Jan 2020, 05:14

Re: IfWinActive with Websites

15 Feb 2020, 05:50

boiler wrote:
14 Feb 2020, 13:09
You should MsgBox % Title "`n" A_LoopField in that spot so you can really see what’s happening.
Thx for this tipp. I tried it now and as I see The Window showed me that "Login - ProtonMail" isn´t the right one because the window said "Login | ProtonMail - Mozilla Firefox". So the Browser name should be in there too.
I changed the Keyword now to "Login | ProtonMail - Mozilla Firefox" and as I see the msgbox both are the same but the case option isn´t working.. It loop everytime again. I tried some other case options too but nothing changed that.
Have anyone an idea what´s the failure?

Code: Select all

Gui, Destroy
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)

run https://mail.protonmail.com/login

Keyword := "Login | ProtonMail - Mozilla Firefox"
!a::
MsgBox,,begin
    WinGetTitle, Title, A   ;Get Window Title
    loop, Parse, Keyword, `,    ;Keyword slicing
    {
		MsgBox,,while
		MsgBox % Title "`n" A_LoopField
        while inStr(Title, A_LoopField) 
			MsgBox % Title "`n" A_LoopField
		{   ;while keyword in title
			MsgBox,,switch
            switch A_LoopField 
			{    ;which keyword
                case "Login | ProtonMail - Mozilla Firefox":
				{
					MsgBox,,found
					Sleep, 5000
					Click
					send,{tab}
					Sleep, 100
					send %temporarybenutzer1%
					Sleep, 500
					send,{tab}
					Sleep, 500
					send %temporarypasswort1%
					send {Enter}
					Sleep, 500
				}
			return
            }
		return
        }
	return
    }
return
}
User avatar
boiler
Posts: 3762
Joined: 21 Dec 2014, 02:44

Re: IfWinActive with Websites

15 Feb 2020, 13:16

You shouldn't have returns where you don't need them. That causes it to exit the subroutine instead of looping through. Also, you don't need the full title if you use SetTitleMatchMode correctly. The code below works for me. Note that I got rid of extra returns and braces. Not sure why you had it waiting 5 seconds either, so I reduced that.

Code: Select all

SetTitleMatchMode, 1
Gui, Destroy
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)

run https://mail.protonmail.com/login

Keyword := "Login | ProtonMail"
!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 "Login | ProtonMail":
					Sleep, 500
					Click
					send,{tab}
					Sleep, 100
					send %temporarybenutzer1%
					Sleep, 500
					send,{tab}
					Sleep, 500
					send %temporarypasswort1%
					send {Enter}
					Sleep, 500
					return
            }
        }
    }
return

Return to “Ask For Help”

Who is online

Users browsing this forum: kczx3 and 57 guests