Windows – Trigger Autohotkey on new window

autohotkeywindow-managerwindows 7

How do I set an action to trigger whenever a new window opens in autohotkey?
For instance, I could set any Windows Explorer window to be marked as "Always on Top" as soon as it comes up. Or I could set any new Skype windows to always open on the second monitor, or always be semi-transparent, etc…

I think autohotkey can achieve this, but I don't know how. I need it to perform some arbitrary action on a new window as soon as it comes up.

Best Answer

AutoHotkey is an off-spin created specifically for hot keys...

You might want to try the original AutoIt instead, it has a lot of automation features, including window events!

More specific, you can find a script here that tracks windows and acts on new windows.

#include <Array.au3>

; Initialize tracking arrays
Global $avWinListPrevious[1][2] = [[0, ""]], $avWinListCurrent

; Monitor unique window handles
While 1
    $avWinListCurrent = WinList("[REGEXPTITLE:.+[ \- ]GIMP]", "GNU Image Manipulation Program")
    For $n = $avWinListCurrent[0][0] To 1 Step -1
   ; Check has title and visible
        If ($avWinListCurrent[$n][0] <> "") And BitAND(WinGetState($avWinListCurrent[$n][1]), 2) Then
       ; Check for already seen
            $fFound = False
            For $i = 1 To $avWinListPrevious[0][0]
                If $avWinListCurrent[$n][1] = $avWinListPrevious[$i][1] Then
                    $fFound = True
                    ExitLoop
                EndIf
            Next

       ; New window found
            If Not $fFound Then
                WinMove("[REGEXPTITLE:.+[ \- ]GIMP]", "GNU Image Manipulation Program", 169, 0, 893, 771 )
            EndIf
        Else
            _ArrayDelete($avWinListCurrent, $n)
        EndIf
    Next
    $avWinListCurrent[0][0] = UBound($avWinListCurrent) - 1
    $avWinListPrevious = $avWinListCurrent
    Sleep(500)
WEnd
Related Question