Activate/click on last X active windows
-
- Posts: 4
- Joined: 27 Nov 2021, 13:56
- Contact:
Activate/click on last X active windows
Hello,
I'm writing a script to kill hanging processes with a shortcut. It works fine but I'd like to improve it by having X last used windows being activated/clicked on so that Windows refreshes some info about processes that don't report correctly.
How would I do that? I saw only activation for current/least recent Window in the docks.
Thanks.
I'm writing a script to kill hanging processes with a shortcut. It works fine but I'd like to improve it by having X last used windows being activated/clicked on so that Windows refreshes some info about processes that don't report correctly.
How would I do that? I saw only activation for current/least recent Window in the docks.
Thanks.
Re: Activate/click on last X active windows
Code: Select all
win := [], win.Push(WinActive("A")), max := 3
Loop {
WinWaitNotActive, A
WinGet, style, Style, A
If (style ~= "0x(9|16)")
Continue
SoundBeep, 1800
If win.Count() >= max
win.RemoveAt(1)
win.Push(WinActive("A"))
}
F3::
list =
For each, hWnd in win {
WinGetTitle, title, ahk_id %hWnd%
list .= (list ? "`n`n" : "") title
WinActivate, ahk_id %hWnd%
}
MsgBox, 64, % "Recent windows (N=" win.Count() ")", %list%
Return
-
- Posts: 4
- Joined: 27 Nov 2021, 13:56
- Contact:
Re: Activate/click on last X active windows
Makes sense, thanks!
What's 0x16 code for the styles? I found this https://www.autohotkey.com/docs/misc/Styles.htm but no 0x16 there
What's 0x16 code for the styles? I found this https://www.autohotkey.com/docs/misc/Styles.htm but no 0x16 there
Re: Activate/click on last X active windows
It's an ad hoc solution. In looking at the styles of various windows, I happened to notice that windows with those styles were not visible windows appearing on the taskbar. The approach might not always work; you can test it if you like. It does work here. I don't know what that style number represents, but it's probably listed somewhere on the Internet. I believe that the forum has some other posts with different approaches to identifying taskbar listings, in case you want to try those, too.
-
- Posts: 4
- Joined: 27 Nov 2021, 13:56
- Contact:
Re: Activate/click on last X active windows
Hmmm. I tried and changed the script from
to
since it was pretty much infinite otherwise. But I'm not too sure that's it, still. Now I'm clicking on random windows and then hear X beeps, but I would like for this to happen automatically, basically loop through windows starting from most recent to least recent.
Code: Select all
If win.Count() >= max
win.Remove(1)
Code: Select all
If win.Count() == max
Break
Re: Activate/click on last X active windows
Here is a recent post that stores all of the HWND values in an array. You can probably adapt it. Feel free to ask questions.
viewtopic.php?p=431802#p431802
The adaptation is below.
This is a demonstration. Pressing F3 will activate the three windows.
What the script does with F3: "having X last used windows being activated/clicked". Before you change it, try it the way it is, to see if the script achieves that functionality.
viewtopic.php?p=431802#p431802
The adaptation is below.
Code: Select all
win := [], win.Push(WinActive("A")), max := 3
Loop {
WinWaitNotActive, A
WinGetTitle, ttitle, A
WinGet, proc, ProcessName, A
SplitPath, proc,,,, proc
WinGetClass, class, %winTitle%
If (ttitle = "" || ttitle = "Program Manager" && proc = "Explorer" || class = "#32770")
Continue
SoundBeep, 1800
If win.Count() >= max
win.RemoveAt(1)
win.Push(WinActive("A"))
}
F3::
clist =
For each, hWnd in win {
WinGetTitle, ttitle, ahk_id %hWnd%
clist .= (clist ? "`n`n" : "") ttitle
WinActivate, ahk_id %hWnd%
}
MsgBox, 64, % "Recent windows (N=" win.Count() ")", %clist%
Return
What the script does with F3: "having X last used windows being activated/clicked". Before you change it, try it the way it is, to see if the script achieves that functionality.
-
- Posts: 4
- Joined: 27 Nov 2021, 13:56
- Contact:
Re: Activate/click on last X active windows
I see what the problem was, I placed the "Loop" in a wrong position and it stopped execution of some things in my script, it is supposed to work infinitely and collect on the fly. I assume there''s no non-infinite way that you can use e.g. on button click rather than having that running at all times?
Also, I noticed this has duplicates problem, but I'll try to work my way around that.
Thanks again!
Also, I noticed this has duplicates problem, but I'll try to work my way around that.
Thanks again!
Re: Activate/click on last X active windows
The loop simply tracks the recent windows. You can remove the beep. If you had to activate it on demand, it could not track anything until that time, but you could still do that by adding a hotkey or some other condition.