Set before last window on top possible? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
peter_ahk
Posts: 118
Joined: 13 Feb 2024, 14:49

Set before last window on top possible?

01 May 2024, 00:08

hello folks

for my macro launcher i have a hotkey routine included to set the last found window on top but i would also like to have a version i can put behind a glabel on a button but if i do so ofc that gui is gonna be the last found window so i like to know can i find the before last window? i cant find a anwser to this so i ask here.

this is my routine i can run with a hotkey

Code: Select all

AOT:
	Winset, Alwaysontop, , A
	return
Rohwedder
Posts: 7705
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Set before last window on top possible?  Topic is solved

01 May 2024, 01:11

Hallo,
try:

Code: Select all

DllCall("RegisterShellHookWindow", "UInt", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "WinActivated")
Return

q::WinActivate,% PreviousWin ; activates the previously active window

WinActivated(wParam, lParam)
{
	Global ActiveWin, PreviousWin
	If (wParam = 4 OR wParam = 32772) ; WINDOWACTIVATED
		PreviousWin := ActiveWin, ActiveWin := "ahk_id " lParam
}
WinActivated is always called when a window becomes active and remembers this (= ActiveWin) and the previous one (= PreviousWin)
peter_ahk
Posts: 118
Joined: 13 Feb 2024, 14:49

Re: Set before last window on top possible?

01 May 2024, 01:50

Rohwedder
thnx ill play around with this tonight and hopefully come back to give this the solution mark :)
peter_ahk
Posts: 118
Joined: 13 Feb 2024, 14:49

Re: Set before last window on top possible?

01 May 2024, 13:59

Rohwedder wrote:
01 May 2024, 01:11
Hallo,
try:

Code: Select all

DllCall("RegisterShellHookWindow", "UInt", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "WinActivated")
Return

q::WinActivate,% PreviousWin ; activates the previously active window

WinActivated(wParam, lParam)
{
	Global ActiveWin, PreviousWin
	If (wParam = 4 OR wParam = 32772) ; WINDOWACTIVATED
		PreviousWin := ActiveWin, ActiveWin := "ahk_id " lParam
}
WinActivated is always called when a window becomes active and remembers this (= ActiveWin) and the previous one (= PreviousWin)
works like a charm thank you, i ended up using it like this (with the dllcall in startup section and the function waaaaay down)

Code: Select all

AOTButton:
	WinActivate,% PreviousWin ; activates the previously active window
	Winset, Alwaysontop, , A
	return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Google [Bot] and 111 guests