Lauch Infinite Subroutines with SetTimer Command

autohotkey

62 просмотра

1 ответ

What I'm trying to achieve is to launch infinite subroutines using the SetTimer command. The code below doesn't work obv, but it should be pretty clear what I'm trying to do. Anyway for every time I press F1 I want to start a new subroutine, with a different name

guiCount := 0
f1::    
guiCount++
drawFrameAroundWin(WinExist("a"), "Red", 5, 1) 
WinGetActiveTitle, activeWinTitleFrame
wingetpos,activeWinTitleFrameX,,,,%activeWinTitleFrame%
SetTimer, Window%guiCount% 
return

Window%guiCount%: 
wingetpos,activeWinTitleFrameX2,,,,%activeWinTitleFrame%
    if (activeWinTitleFrameX != activeWinTitleFrameX2)
        {
        Gui,Destroy
        SetTimer, window%guiCount%, off
        }
return
Автор: user3159140 Источник Размещён: 08.11.2019 11:08

Ответы (1)


1 плюс

As you know, Subroutines cannot be declared with a variable as you are trying. You seem to be trying to use Threads, unfortunately Official AutoHotkey lacks them, but there are 3 options: AutoHotkey.dll provides thread like capabilities (google it), you can modify and save a new script and run it separate each time you want to create a new window border, or you can just use a set time with a timer (if it doesn't have to destroy the gui in a precise matter) and destroy the windows in order from first created to last.

Below demonstrates the 3rd option, not a perfect implementation:

guiNumArr := []

F1::
  WinGetActiveStats, Title, Width, Height, X, Y
  guiCurrent := drawFrameAroundWin(Width, Height)
  guiNumArr.push(guiCurrent)
  Gui, %guiCurrent%:Show, NoActivate ; The Gui will not steal keyboard focus
  SetTimer, guiDestroy, 2000
Return

guiDestroy:
    if (guiNumArr.length()) {
        x := guiNumArr.RemoveAt(1)
        gui, %x%:destroy 
        return
    }
    else
        SetTimer, guiDestroy, Off
return

drawFrameAroundWin(TW:=320, TH:=240, BorderThickness:=3, BorderColor:="0000FF") {
    static guiNumber := 0

    guiNumber++
    colors := ["Red", "Yellow", "Blue", "Green"]

    random, x, 1, 4
    BorderColor := colors[x]

    Gui, %guiNumber%:Margin, %BorderThickness%, %BorderThickness%
    Gui, %guiNumber%:Color, %BorderColor%
    Gui, %guiNumber%:Add, Text, w%TW% h%TH% 0x6 ; Draw a white static control
    Gui, %guiNumber%:+LastFound 
    WinSet, TransColor, FFFFFF
    Gui, %guiNumber%: -Caption +AlwaysOnTop +ToolWindow

    Return guiNumber
}
Автор: errorseven Размещён: 20.08.2016 09:24
Вопросы из категории :
32x32