0
votes

I have a simple AHK script that opens a website in my default browser (Firefox).

NumPad7::
    Run, www.bbc.com 
return

When I run the program outside of Firefox, it opens the website in a new tab as intended. However, when I am in Firefox and run the script, Firefox is deactivated although the website does open. If I use the hotkey an even number of times it works even when Firefox is open. I have tried using WinActivate after the command but it doesn't work.

Any idea how I can keep Firefox active?

1
Try adding WinWait before WinActivate. Does it occur in all websites you want open this way?user3419297
@user3419297 I tried WinWait and WinWait[not]Active before WinActivate, neither worked with any of the sites I tried.user3586940
Do not use WinWaitActive before WinActivate. And what happens if you use another key instead of NumPad7 e.g. F1?user3419297
@user3419297 Same problem with any other key. I was using WinWaitNotActive, hoping the window would become inactive and then I could activate it again.user3586940

1 Answers

1
votes

Try to find out which window gets active, this way:

NumPad7::
    Run, www.bbc.com 
    Sleep 500 ; or more
    WinGetTitle, WinTitle, A
    WinGetClass, ActiveClass, A
    MsgBox, Active Window:`n"%WinTitle%"`nahk_class "%ActiveClass%"
return

And this should work:

NumPad7::
    Run, www.bbc.com 
    WinWait, BBC - Homepage - Mozilla Firefox
    WinActivate, BBC - Homepage - Mozilla Firefox
return