Page 1 of 1

How to loop through Chrome windows while excluding VS Code editor

Posted: 22 Apr 2021, 18:40
by balkinishu
Both Chrome and VS Code share ahk_class Chrome_WidgetWin_1. I'd like to loop through my chrome windows without having VS Code windows in the rotation. How do I modify the below script to do that? I know that VS Code has ProcessName Code.exe which is different than all the chrome instances which have chrome.exe; but how do I prevent a VS code window from activating if it's the next window in the loop.

Code: Select all


	#g::
	{  
		WinGetClass, ActiveClass, A
		WinGet, n_instances, List, ahk_class %ActiveClass%
		if (n_instances > 1)
				WinActivateBottom, ahk_class %ActiveClass%,,Tabs Outliner,
		return
		
		;  WinGet, p_name, ProcessName , ahk_class %ActiveClass%
	}
	




Re: How to loop through Chrome windows while excluding VS Code editor  Topic is solved

Posted: 22 Apr 2021, 19:03
by mikeyww
You can add the process name to the WinTitle.

Explained: Multiple criteria

Re: How to loop through Chrome windows while excluding VS Code editor

Posted: 22 Apr 2021, 20:32
by balkinishu
Thanks for guiding me to the right documentation section Mikeyww. Much appreciated.

For posterity, here's the revised code.

Code: Select all


#capslock:: F_activate_next_instance()  ; <sys> rotate through different instances of the active program

F_activate_next_instance(){
	WinGetClass, ActiveClass, A
	WinGet,      p_name,      ProcessName , ahk_class %ActiveClass%
	WinGet,      n_instances, List,         ahk_class %ActiveClass%
	if (n_instances > 1)
		WinActivateBottom, ahk_class %ActiveClass% ahk_exe %p_name%,,Tabs Outliner,
	return	
}


Re: How to loop through Chrome windows while excluding VS Code editor

Posted: 22 Apr 2021, 21:02
by mikeyww
If you want to activate the Chrome window on the bottom, the following script alone may also work.

Code: Select all

#g::WinActivateBottom, ahk_exe chrome.exe,, Tabs Outliner
This might not be an ideal hotkey choice (seems to activate a widgets menu).

Re: How to loop through Chrome windows while excluding VS Code editor

Posted: 22 Apr 2021, 23:11
by balkinishu
It's actually pretty easy to disable the Microsoft game bar from the Windows 10 settings menu to free up the #g key combo. While you're at it, I would also suggest disabling windows narrator and the magnifying widget as well.

https://www.windowscentral.com/how-disable-and-remove-game-bar-windows-10-creators-update

Thanks for the code suggestion, I actually want to keep my revised script the way it is so it applies to any active program. I had problems with some other programs as well as chrome. I just thought my problem would be clearer if I presented it as a specific Chrome problem.

I am sorta curious about how I would go about cycling in the other direction, but it's not something that's annoying me enough to expend effort on right now.

Re: How to loop through Chrome windows while excluding VS Code editor

Posted: 23 Apr 2021, 05:31
by mikeyww
OK. Sending to bottom: WinSet

Re: How to loop through Chrome windows while excluding VS Code editor

Posted: 24 Apr 2021, 23:14
by balkinishu

Code: Select all

!capslock:: activate_last_instance()

activate_last_instance(){
	WinGetClass, ActiveClass, A
	WinGet,      p_name,      ProcessName , ahk_class %ActiveClass%
	WinGet,      n_instances, List,         ahk_class %ActiveClass%
	
	if (n_instances > 1)
		WinSet, Bottom,, A
	WinActivate, ahk_class %ActiveClass% ahk_exe %p_name%,,Tabs Outliner,
	return	

}