Skip to content

Instantly share code, notes, and snippets.

@tdalon
Last active October 13, 2023 12:18
Show Gist options
  • Save tdalon/84d9caea0368ab0420b81363c2048705 to your computer and use it in GitHub Desktop.
Save tdalon/84d9caea0368ab0420b81363c2048705 to your computer and use it in GitHub Desktop.
AutoHotkey Script to Get Main Microsoft Teams Window
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
@tdalon
Copy link
Author

tdalon commented Jan 27, 2021

See implementation explanation in this blog post: Get Teams Window Autohotkey
This is implemented in the PowerTools Teamsy and Teams Shortcuts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment