0
votes

I am having trouble with my AHK loop command and was hoping someone out there could help me out. I have a situation where I have to connect to customer sites daily and authenticate myself with some key strokes (click submit, enter etc). If i connect to a customer for the first time that day, I have to authenticate w a reason. Any connections made to that customer that day to any other server i dont need to type in the reason. If i have entered the reason for the day, this loop works great:

#+r::
Loop
{
WinWait, Search - Google Chrome
IfWinNotActive, Search - Google Chrome, WinActivate1817, Search - Google Chrome
WinWaitActive, Search - Google Chrome
Sleep, 100
Send, {ENTER}
WinWait, Search Hosts - Google Chrome
IfWinNotActive, Search Hosts - Google Chrome, WinActivate, Search Hosts - Google Chrome
WinWaitActive, Search Hosts
Send, +{TAB}+{TAB}{ENTER}
}
return

Here is my issue, I also need this loop to run:

#+s::
Loop
{
WinWait, CRM Information
IfWinNotActive, CRM Information, WinActivate, CRM Information
WinWaitActive, CRM Information
Send, +{TAB}+{TAB}+{TAB}HPF{ENTER}
}
return

I know i can only run one loop at a time though. Essentially what i want to happen is to have some kind of If/else statement. I always need the first script running, but only need the second script to run if it is my first time connecting to the customer for the day. So i need to move number two into one. I always need the first one running, and if it sees CRM Information chrome screen title bar run the second part and if it doesnt see it, loop back to beginning.

I hope that makes sense!

1

1 Answers

0
votes

Always use AutoHotkey from http://ahkscript.org/ (current version, new official website)! AutoHotkey from autohotkey.com is outdated and you may have some problems running scripts with it!

If I understand you correctly, you need to run first script anytime you press hotkey, but run second script only when you press hotkey first time. I made a script which after you run it, it will execute first and second script after you press hotkey first time. All subsequent hotkey presses will execute only first script. Here is script:

runcounter:=0

#+r::
Loop
{
    WinWait, Search - Google Chrome
    IfWinNotActive, Search - Google Chrome, WinActivate1817, Search - Google Chrome
    WinWaitActive, Search - Google Chrome
    Sleep, 100
    Send, {ENTER}
    WinWait, Search Hosts - Google Chrome
    IfWinNotActive, Search Hosts - Google Chrome, WinActivate, Search Hosts - Google Chrome
    WinWaitActive, Search Hosts
    Send, +{TAB}+{TAB}{ENTER}

    runcounter:= runcounter + 1

    if (runcounter = 1)
    {
        Loop
        {
            WinWait, CRM Information
            IfWinNotActive, CRM Information, WinActivate, CRM Information
            WinWaitActive, CRM Information
            Send, +{TAB}+{TAB}+{TAB}HPF{ENTER}
        }
    }

}
return



EDIT From the comment I understand that you have 3 scripts. First one is Search - Google Chrome, second one is Search Hosts - Google Chrome and third one is CRM Information. Now you need to run when script runs first time to run all three scripts (1,2,3). All subsequent runs should only run first script. Is that what you want script to do? Here is code for it:

runcounter:=0

#+r::
Loop
{
    WinWait, Search - Google Chrome
    IfWinNotActive, Search - Google Chrome, WinActivate1817, Search - Google Chrome
    WinWaitActive, Search - Google Chrome
    Sleep, 100
    Send, {ENTER}

    runcounter:= runcounter + 1

    if (runcounter = 1)
    {
        Loop
        {

            WinWait, Search Hosts - Google Chrome
            IfWinNotActive, Search Hosts - Google Chrome, WinActivate, Search Hosts - Google Chrome
            WinWaitActive, Search Hosts
            Send, +{TAB}+{TAB}{ENTER}

            WinWait, CRM Information
            IfWinNotActive, CRM Information, WinActivate, CRM Information
            WinWaitActive, CRM Information
            Send, +{TAB}+{TAB}+{TAB}HPF{ENTER}
        }
    }

}
return