SetActiveWindowTracking.ahk:
; ====================================================================================================================== ; Function: Sets active window tracking (activating the window the mouse is on) either on or off. ; AHK version: AHK_L ; Tested on: Win XP (x86/U32), Vista (x86/U32), and 7 (x64/U64) ; Parameters: ; Track - Set active window tracking on or off ; Values: 1 (True) = On ; 0 (False) = Off ; -1 = Restore system settings ; OnTop - Determines whether or not activated windows should be brought to the top ; Values: True = Yes ; False = No ; Default: True ; Delay - Number of milliseconds to delay before activating the window under the mouse pointer ; Default: 1000 ; Return value: ; None ; Remarks: ; The function stores the current system settings on the first call. To restore these settings call the function ; passing -1 in Track. Setting changes are not stored permanently in the registry and will be lost after a restart. ; ====================================================================================================================== SetActiveWindowTracking(Track, OnTop = True, Delay = 1000) { ; http://msdn.microsoft.com/en-us/library/ms724947%28VS.85%29.aspx ; SPI_GETACTIVEWINDOWTRACKING = 0x1000 ; SPI_GETACTIVEWNDTRKZORDER = 0x100C ; SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002 ; SPI_SETACTIVEWINDOWTRACKING = 0x1001 ; SPI_SETACTIVEWNDTRKZORDER = 0x100D ; SPI_SETACTIVEWNDTRKTIMEOUT = 0x2003 Static FirstCall := True Static SPITrack := 0 Static SPIOnTop := 0 Static SPIDelay := 0 Static SPI := "User32.dll\SystemParametersInfo" If (FirstCall) { DllCall(SPI, "UInt", 0x1000, "UInt", 0, "UIntP", SPITrack, "UInt", False) DllCall(SPI, "UInt", 0x100C, "UInt", 0, "UIntP", SPIOnTop, "UInt", False) DllCall(SPI, "UInt", 0x2002, "UInt", 0, "UIntP", SPIDelay, "UInt", False) FirstCall := False } If (Track = -1) { Track := SPITrack OnTop := SPIOnTop Delay := SPIDelay } Else If !(Track) { OnTop := False Delay := 0 } DllCall(SPI, "UInt", 0x1001, "UInt", 0, "Ptr", Track, "UInt", False) DllCall(SPI, "UInt", 0x100D, "UInt", 0, "Ptr", OnTop, "UInt", False) DllCall(SPI, "UInt", 0x2003, "UInt", 0, "Ptr", Delay, "UInt", False) }Sample:
#NoEnv #Persistent #Include SetActiveWindowTracking.ahk OnExit, AppExit SetActiveWindowTracking(True) Return AppExit: SetActiveWindowTracking(-1) ExitAppNote: It may run with AHK Basic if you change all types "Ptr" to "UInt" in the DllCalls (*not tested*).