Last active
February 28, 2025 15:15
-
-
Save tdalon/84d9caea0368ab0420b81363c2048705 to your computer and use it in GitHub Desktop.
AutoHotkey Script to Get Main Microsoft Teams Window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Teams_GetMainWindow(){ | |
; See implementation explanations here: https://tdalon.blogspot.com/get-teams-window-ahk | |
; Syntax: hWnd := Teams_GetMainWindow() | |
WinGet, WinCount, Count, ahk_exe Teams.exe | |
If (WinCount = 0) | |
GoTo, StartTeams | |
If (WinCount = 1) { | |
TeamsMainWinId := WinExist("ahk_exe Teams.exe") | |
return TeamsMainWinId | |
} | |
; Get main window via Acc Window Object Name | |
WinGet, id, List,ahk_exe Teams.exe | |
Loop, %id% | |
{ | |
hWnd := id%A_Index% | |
oAcc := Acc_Get("Object","4",0,"ahk_id " hWnd) | |
sName := oAcc.accName(0) | |
If RegExMatch(sName,".* \| Microsoft Teams, Main Window$") { | |
return hWnd | |
} | |
} | |
; Fallback solution with minimize all window and run exe | |
If WinActive("ahk_exe Teams.exe") { | |
GroupAdd, TeamsGroup, ahk_exe Teams.exe | |
WinMinimize, ahk_group TeamsGroup | |
} | |
StartTeams: | |
fTeamsExe = C:\Users\%A_UserName%\AppData\Local\Microsoft\Teams\current\Teams.exe | |
If !FileExist(fTeamsExe) { | |
return | |
} | |
Run, %fTeamsExe% | |
WinWaitActive, ahk_exe Teams.exe | |
TeamsMainWinId := WinExist("A") | |
PowerTools_RegWrite("TeamsMainWinId",TeamsMainWinId) | |
return TeamsMainWinId | |
} ; eofun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See implementation explanation in this blog post: Get Teams Window Autohotkey
This is implemented in the PowerTools Teamsy and Teams Shortcuts