Code: Select all
SetBatchLines, -1
Return ; end of auto-execute section
;-------------------------------------------------------------------------------
Watchdog(wParam, lParam := "") { ; monitor activating windows
;-------------------------------------------------------------------------------
static init := DllCall("RegisterShellHookWindow", Ptr, A_ScriptHwnd)
, MsgNum := DllCall("RegisterWindowMessage", Str, "SHELLHOOK")
, neglect := OnMessage(MsgNum, "Watchdog")
, CleanUp := {base: {__Delete: "Watchdog"}}
If Not IsObject(CleanUp) {
OnMessage(MsgNum, "")
DllCall("DeregisterShellHookWindow", Ptr, A_ScriptHwnd)
}
If (wParam = 1) ; HSHELL_WINDOWCREATED
Or (wParam = 4) ; HSHELL_WINDOWACTIVATED
Or (wParam = 32772) ; HSHELL_RUDEAPPACTIVATED
Guard(lParam) ; alert the guard about a new active window
}
;-------------------------------------------------------------------------------
Guard(hActive) { ; toggle mouse on/off if a certain window is active
;-------------------------------------------------------------------------------
WinGetTitle, Title, ahk_id %hActive%
If InStr(Title, "Notepad") { ; toggle mouse off
BlockInput, MouseMove
ShowMouse(False)
}
Else { ; toggle mouse on
BlockInput, MouseMoveOff
ShowMouse(True)
}
}
;-------------------------------------------------------------------------------
ShowMouse(bShow := True) { ; show/hide the mouse cursor
;-------------------------------------------------------------------------------
static CursorList := "32512, 32513, 32514, 32515, 32516, 32640, 32641"
. ",32642, 32643, 32644, 32645, 32646, 32648, 32649, 32650, 32651"
If bShow ; SPI_SETCURSORS := 0x57
Return, DllCall("SystemParametersInfo"
, UInt, 0x57, Int, 0, Int, 0, Int, 0)
; create a blank cursor
VarSetCapacity(ANDmask, 32 * 4, 0xFF)
VarSetCapacity(XORmask, 32 * 4, 0x00)
BlankCursor := DllCall("CreateCursor", Int, 0, Int, 0, Int, 0
, Int, 32, Int, 32, Ptr, &ANDmask, Ptr, &XORmask)
; set all system cursors to blank, each needs a new copy
Loop, Parse, CursorList, `,, %A_Space%
{
CursorHandle := DllCall("CopyImage", UInt, BlankCursor
, Int, 2, Int, 0, Int, 0, Int, 0)
DllCall("SetSystemCursor", UInt, CursorHandle, Int, A_Loopfield)
}
}