Re: Checking to see if a Window is no longer at the front

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Checking to see if a Window is no longer at the front

21 Sep 2018, 08:36

[Mod edit: Original first post was removed as it was replaced with spam]

Code: Select all

msg := DllCall("RegisterWindowMessageW", "Str", "SHELLHOOK", "UInt")
DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
OnMessage(msg, "WM_SHELLHOOKMESSAGE")
OnExit("Deregister")

Esc::ExitApp
q::
	hTarget := WinActive("A")
	WinGetTitle title, % "ahk_id " hTarget
	MsgBox % "Now watching: " title
Return

WM_SHELLHOOKMESSAGE(wParam, lParam, msg, hwnd) {
	static HSHELL_WINDOWACTIVATED := 0x0004
		, HSHELL_RUDEAPPACTIVATED := 0x8004
		, PREVIOUS_LPARAM := 0

	global hTarget

	if (wParam = HSHELL_WINDOWACTIVATED || wParam = HSHELL_RUDEAPPACTIVATED)
	{
		if (PREVIOUS_LPARAM = hTarget)
		{
			ToolTip % "Window focus changed"
			SetTimer RemoveTooltip, -1000
		}
	}

	PREVIOUS_LPARAM := lParam
}

RemoveTooltip() {
	ToolTip
}

Deregister() {
	DllCall("DeregisterShellHookWindow", "Ptr", A_ScriptHwnd)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 361 guests