WinActivating Programs Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
blad4
Posts: 315
Joined: 07 Oct 2015, 11:06

WinActivating Programs

07 Feb 2020, 07:22

I use below to cycle through open programs, and all is mostly fine, using Win10. There often is a slight delay however, in that the activation of a Window is slower than the requests, so say I send the command twice, it will only open the next one. Then if I resend, it will open the next one fine, showing that there was an overall lag (maybe between the programs being resource heavy), and it doesn't simply skip to the next program which would indicate that my command got sent but failed.

If using Left click for this, is there a more efficient way using WinWait and IfWinActive and Keywait, to additionally employ the following two criteria:

1) Count number of clicks and match next program activation. E.g. pressed Left 5 times, say within 1000ms, program 5 is activated
2) Check what the latest click was and ensure that the correct program is open, no matter the lag of the program itself activating

Code: Select all

if vaRtt=1
{
Winactivate 1
return
}
if vaRtt=2
{
Winactivate 2
return
}
if vaRtt=3
{
Winactivate 3
return
}
if vaRtt=4
{
Winactivate 4
return
}
Albireo
Posts: 1778
Joined: 16 Oct 2013, 13:53

Re: WinActivating Programs

07 Feb 2020, 09:50

Don't know if it could be of any help, but to register mouse clicks I would do the following .:

Code: Select all

#Persistent
...
LButton::
...
Return
To keep track of the time I would use .: SetTimer example #3
wbm1113
Posts: 18
Joined: 28 Aug 2018, 11:19

Re: WinActivating Programs  Topic is solved

07 Feb 2020, 20:30

I don't know how to do the click-counting within a certain timeframe (1000 ms). It seems like that would interfere with normal clicking behavior. That said, this might help you with the other things you're trying to achieve:

Code: Select all

global vaRtt := 1

Gui, Show, w300 h300, 1 
if ActivateByNumber(vaRtt) ; success
    MsgBox Success!
else
    MsgBox Better luck next time!


Gui, Show, w300 h300, 2
if ActivateByNumber(vaRtt) ; fail
    MsgBox Success!
else
    MsgBox Better luck next time!
return

ActivateByNumber(Number) {
    if(Number=0)
        return 0 ; vaRtt needs to be 1, 2, 3, etc. or higher in order to proceed

    ActiveTitle := ""
    WinActivate % Number ; activates 1 

    While(ActiveTitle!=Number) { ; continues activating '1,' until it is active
        WinGetActiveTitle, ActiveTitle
        Sleep 50
        WinActivate % Number
        if(A_Index>40) ; 40 iterations * 50 ms in the sleep command = 2 total seconds of waiting
            return 0 ; if 2 seconds is exceeded, return 0
    }

    return 1 ; otherwise return 1
}
blad4
Posts: 315
Joined: 07 Oct 2015, 11:06

Re: WinActivating Programs

09 Feb 2020, 07:33

Thank you guys, both a big help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 361 guests