I have shared previously how to get the active Teams meeting window with AutoHotkey with 2 ways: one prompting the user and an improved one using FindText.
I share now a better, more robust solution based on the UIAutomation library.
Key points
I identify the Teams meeting window by looking for an UIA Element with the AutomationId=microphone-button)
(TeamsEl.FindFirstBy("AutomationId=microphone-button"))
To exclude Meetings on-hold from the active meeting, I look for the existence of the Resume button by its Name. (TeamsEl.FindFirstByName("Resume"))
I check if the meeting window is minimized by the existence of TeamsEl.FindFirstByNameAndType("Navigate back to call window.", "button")
In case the meeting window is minimized, you might want to restore/ maximize it to access specific meeting actions only available in the maximized window.
This is why I have added the input arguments in the main function.
Implementation
The latest implementation is available in the Teams.ahk library -> Teams_GetMeetingWindow()
The implementation looks simply like this (Gist code below might be different from latest version in repo):
This file contains 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_GetMeetingWindow(Minimize:=false,showTrayTip:=true){ ; @fun_teams_getmeetingwindow@ | |
; Syntax: | |
; hWnd := Teams_GetMeetingWindow(Minimize:=true) | |
; If window is not found, hwnd is empty | |
; Input Arguments: | |
; Minimize: if true, minimized (aka Call in Progress) meeting window can be returned | |
; | |
; See implementation explanations here: | |
; https://tdalon.blogspot.com/2022/07/ahk-get-teams-meeting-win.html | |
; Does not require window to be activated | |
UIA := UIA_Interface() | |
TeamsExe := Teams_GetExeName() | |
WinGet, Win, List, ahk_exe %TeamsExe% | |
/* | |
If restoreWin | |
WinGet, curWinId, ID, A | |
*/ | |
Loop %Win% { | |
WinId := Win%A_Index% | |
; WinActivate, ahk_id %WinId% | |
TeamsEl := UIA.ElementFromHandle(WinId) | |
;MsgBox % TeamsEl.Name | |
If Teams_IsMeetingWindow(TeamsEl) { | |
If (!Minimize) | |
If Teams_IsMinMeetingWindow(TeamsEl) | |
Continue | |
return WinId | |
} | |
} ; End Loop | |
/* | |
If (restoreWin) | |
WinActivate, ahk_id %curWinId% ; restore win | |
*/ | |
If (showTrayTip) | |
TrayTip, Could not find Meeting Window! , No active Teams meeting window found!,,0x2 | |
} ; eofun | |
; ------------------------------------------------------------------------------------------------------------------- | |
Teams_IsMeetingWindow(TeamsEl,ExOnHold:=true){ | |
; does not return true on Share / Call in progress window | |
; If Meeting Reactions Submenus are opened AutomationId are not visible. | |
If (ExOnHold) { | |
Name := Teams_GetLangName("Resume","Resume") | |
If (Name="") | |
return | |
} | |
If TeamsEl.FindFirstBy("AutomationId=microphone-button") { | |
If (ExOnHold) { ; exclude On Hold meeting windows | |
If TeamsEl.FindFirstByName(Name) ; Exclude On-hold meetings with Resume button | |
return false | |
} | |
return true | |
} | |
return false | |
} ; eofun | |
; ------------------------------------------------------------------------------------------------------------------- | |
Teams_IsMinMeetingWindow(TeamsEl) { | |
; Return true if the window is a minimized meeting window | |
; Check for button "Navigate back" | |
Name := Teams_GetLangName("NavigateBack","Navigate back to call window.") | |
If InStr(Lang,"en-") or (Lang="") | |
Name := | |
If (Name="") | |
return | |
El := TeamsEl.FindFirstByNameAndType(Name, "button") ; | |
If El | |
return true | |
Else | |
return false | |
} ; eofun |