0
votes

I have 2 repeating actions that I want constantly waiting. Specifically, there are a couple of windows that, when they appear, I want AutoHotkey to perform an action on. For example, I want to move and resize the window with title "Window 1", and send a y keypress to "Window 2". So I have this:

win1.ahk

While, 1
{
    WinWaitActive, Window 1
    WinMove, Window 1, , 100, 100, 800, 600
}

win2.ahk

While, 1
{
    WinWaitActive, Window 2
    send y
}

My question is whether it is possible to put multiple such actions in the same AutoHotkey script. If I have 30 different windows that I want to wait on, do I need 30 individual .ahk scripts with this format, or is it possible to register several actions all in a single script?

1

1 Answers

0
votes

No, just one script with a timer and a switch (a switch per action if you're sending keystrokes so they don't repeatedly send). Example, take out the notepadSentKey variable and see what happens when you open a new notepad.

#Persistent
SetTimer, DoStuff, 100
notepadSentKey := false
return

DoStuff:
{
    IfWinActive, % "Untitled - Notepad"
    {
        WinMove, A,, 0, 0, 500, 200
        if (!notepadSentKey) {
            Send, Hello there{!}
            notepadSentKey := true
        }
    }
    IfWinActive, % "Calculator"
    {
        WinGetPos, x, y, w, h
        WinMove, A,, % (A_ScreenWidth/2)-(w/2), % (A_ScreenHeight/2)-(h/2)
    }
    return
}