How to retrieve last activated ahk_id & ClassNN Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

How to retrieve last activated ahk_id & ClassNN

25 Apr 2017, 00:00

How can I retrieve information about the last accessed window (ahk_id, ClassNN)?

Current active window: ahk_id Current_Win
Currently active ClassNN of currently active window: Current_WinNN
Last active window: ahk_id Last_Win
Last active ClassNN of the last active window: Last_WinNN
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: How to retrieve last activated ahk_id & ClassNN

25 Apr 2017, 01:08

There are plenty of examples of RegisterShellHookWindow which you can use to detect changes of the active window. You can use that as a trigger to set ahk_id Current_Win and move the old value to ahk_id Last_Win.

ClassNN belongs to a control and not a window, or do you mean ahk_class?
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: How to retrieve last activated ahk_id & ClassNN

25 Apr 2017, 04:08

Nextron wrote:There are plenty of examples of RegisterShellHookWindow which you can use to detect changes of the active window. You can use that as a trigger to set ahk_id Current_Win and move the old value to ahk_id Last_Win.

ClassNN belongs to a control and not a window, or do you mean ahk_class?
From googling it, RegisterShellHookWindow seems to be some MSDN stuff, which I am not familiar with.
Is there another way of achieving the same goal without MSDN?

And yes, the last accessed ClassNN is what I want.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: How to retrieve last activated ahk_id & ClassNN  Topic is solved

25 Apr 2017, 10:28

Or this:

Code: Select all

#Persistent
SetTimer last_accessed_windows, 300
return

	last_accessed_windows:
WinGet, CurrentActive_ID, ID, A
If (CurrentActive_ID = NewActive_ID)
	ControlGetFocus, LastFocusedControl, A
else
{
	LastActive_ID = %NewActive_ID%
	NewActive_ID := CurrentActive_ID
	WinGetTitle, NewActiveTitle,  ahk_id %NewActive_ID%	
	WinGetTitle, LastActiveTitle,  ahk_id %LastActive_ID%
	ControlGetFocus, NewFocusedControl, A
	CoordMode, ToolTip, Screen
	ToolTip, Current active window:`nTitle: %NewActiveTitle%`nLast Focused Control: %NewFocusedControl%`nID: %NewActive_ID%`n`nLast active window:`nTitle: %LastActiveTitle%`nLast Focused Control: %LastFocusedControl%`nID: %LastActive_ID%, 0, 0
}
return
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: How to retrieve last activated ahk_id & ClassNN

26 Apr 2017, 01:22

Exactly what I wanted. Thank you GEV.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: How to retrieve last activated ahk_id & ClassNN

27 Apr 2017, 01:08

Code: Select all

Gui +LastFound
DllCall( "RegisterShellHookWindow", UInt, WinExist() )
OnMessage( DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" ), "ShellMessage" )
global LastActiveWindowID := WinActive("A")
Return ;                                          // End of Auto-Execute Section //

ShellMessage( wParam, lParam )  {
  If ( wParam = 4 And WinExist( "ahk_id " lParam ) ) { ; HSHELL_WINDOWACTIVATED = 4
     WinGetTitle, LastActiveTitle,  ahk_id %LastActiveWindowID%
     WinGetTitle, NewActiveTitle, % "ahk_id " LastActiveWindowID := lParam
     ToolTip, Current active window:`nTitle: %NewActiveTitle%`n`nLast active window:`nTitle: %LastActiveTitle%, 0, 0
  }
}
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww and 145 guests