WinGet

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
daywalker
Posts: 32
Joined: 18 Jun 2019, 01:37

WinGet

11 May 2022, 00:56

1) I dont get the Winget-command run properly to inlclude and exclude WinTitles in same commandline. Teams.exe (which i wanted to exclude) is still in the result. See example code below.

2) Working with this issue, for me raises this additional question if this is a valid code (using group to be exclude in another group):
GroupAdd, Chrome_WidgetWin, ahk_class Chrome_WidgetWin_1,,, ahk_group Chrome_WidgetWin_exclude ?

Thanks!

My example:

Code: Select all

	
	SetTitleMatchMode, 1
	SetTitleMatchMode, fast
	DetectHiddenWindows, Off

	;Negative Group
	;GroupAdd, Chrome_WidgetWin_exclude, Program Manager 
	GroupAdd, Chrome_WidgetWin_exclude, ahk_exe explorer.exe  ; instead of "Program Manager"
	GroupAdd, Chrome_WidgetWin_exclude, ahk_exe Teams.exe

	;Positive Group
	GroupAdd, Chrome_WidgetWin, ahk_class Chrome_WidgetWin_0,,, ahk_exe Teams.exe
	GroupAdd, Chrome_WidgetWin, ahk_class Chrome_WidgetWin_1,,, ahk_exe Teams.exe
	;GroupAdd, Chrome_WidgetWin, ahk_class Chrome_WidgetWin_1,,, ahk_group Chrome_WidgetWin_exclude  ; is this working ?

	; WinGet-Test normal
	WinGetTest("1","ahk_class Chrome_WidgetWin_1", "ahk_exe Teams.exe")   ; Returns also Teams.exe windows
	
	; WinGet-Test with groups
	WinGetTest("2","ahk_group Chrome_WidgetWin", "ahk_group Chrome_WidgetWin_exclude") ; Returns also Teams.exe windows
	
	; WinGet-Test with Regex (case insensitive)
	SetTitleMatchMode,RegEx 
	WinGetTest("regex","i)ahk_class Chrome_WidgetWin_*", "i)ahk_exe Teams.exe*") ; Returns also Teams.exe windows


Exitapp

WinGetTest(testname,IncludeTitle,ExcludeTitle)
{
	WinGet, List_Count, Count, %IncludeTitle%,,%ExcludeTitle%
	msgbox Test#%testname%`nCount=%List_Count%
	
	WinGet, List_, List, %IncludeTitle%,,%ExcludeTitle%
	Loop, %List_%  {
		id:=List_%A_Index%
		WinGet, this_ProcessName, ProcessName, ahk_id %id%
		;if (this_ProcessName="teams.exe")  ; workaround to exclude teams.exe
		;	continue
		WinGetClass, this_class, ahk_id %id%
		WinGetTitle, this_title, ahk_id %id%
		WinGetText, this_text, ahk_id %id%
		WinGetPos, X, Y, Width, Height, ahk_id %id%
		WinActivate, ahk_id %id%  ; Brings found window to front
		msgbox Test#%testname%: %A_INDEX%/%List_Count%`n%this_ProcessName%`n%this_class%`n%this_title%`n%this_text%`n%X%, %Y%, %Width%, %Height%`n
	}
}
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: WinGet

11 May 2022, 06:03

Your question is whether an ExcludeTitle parameter can be a WinTitle with ahk_ criteria, rather than just a window title. One can answer this question in a four-line demonstration.

Code: Select all

Run, notepad
WinWait, ahk_exe notepad.exe
WinGet, win, List, ahk_exe notepad.exe,, ahk_exe notepad.exe
MsgBox, 64, Number of windows, %win%
What do you want to happen, or think will happen? What actually happened?
daywalker
Posts: 32
Joined: 18 Jun 2019, 01:37

Re: WinGet

11 May 2022, 06:16

I want to match all windows with ahk_class Chrome_WidgetWin_1 but excluding Teams.exe from the result (Note:Teams.exe has also this class).
All windows with ahk_class Chrome_WidgetWin_1 could be Teams.exe, Chrome.exe,Edge.exe or ...

So my idea would be to use this code
WinGet, List_, List, ahk_class Chrome_WidgetWin_1,,ahk_exe Teams.exe
but it fails as it returns Teams.exe as well.
Where is my mistake?

In the first post, i made different approaches also with regex and groups. When you have Teams installed, you can verify with the code from the first post (Just open Teams.exe without edge or chrome and run the script).
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: WinGet

11 May 2022, 06:23

The main mistake was probably ignoring my last post, which provides the answer to your question.

You could use a window title for your exclusion, or when you act upon the windows in the list, you can check the process name and then skip windows with a certain name.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: fiaztv1, Pianist and 174 guests