April 1, 2021

AutoHotkey: Microsoft Teams Get active meeting window without user prompt

This post is a bit obsolete; see Get Microsoft Teams Meeting Window using UIAutomation for the latest.

The previous solution I have shared to identify the current Microsoft Teams meeting window with AutoHotkey would prompt the user to finally validate the window - in case you have meetings in parallel e.g. with one on hold. I share here a way to skip this user prompt / fully automate the meeting window detection.

Notes

The solution is a mixed of previous solution with 2 additional checks based on FindText (I have already used in a previous post)

FindText is used to exclude on-hold meetings (which contains the Resume UI element/button)
And only include windows with the Leave UI element.

The only drawback of the FindText approach is that it activates the window it checks.
That's why I pre-filter before with the previous approach to minimize window flashing/activation.

I am not 100% sure that the FindText approach works for all. (Might depends on screen resolution) and since I do a hard check if the window contains a Leave element, I have added a parameter to switch it off. (TeamsMeetingWinUseFindText). Set it to 0 to deactivate it.


See also this Gist.
Teams_GetMeetingWindow(useFindText:="" , restore := True){
; See implementation explanations here: https://tdalon.blogspot.com/2021/04/ahk-get-teams-meeting-window.html
If (useFindText="")
useFindText := PowerTools_GetParam("TeamsMeetingWinUseFindText") ; Default 1
If (useFindText) {
If (restore)
WinGet, curWinId, ID, A
ResumeText:="|<>*138$51.zzzzzzzzw3zzzzzzzUDzzzzzzwtzzzzzzzbA64NU1kQ1423A04FUtUQNa8aAX0EXAlY1a9zUNaAbwt4Y0AlYHb4461aAkTzzzzzzzzU" ; FindText for Resume
LeaveText:="|<>*168$66.zzzzzzzzzzzzzzzzDzzzzzy01zzDzzzzzs00TzDzzzzzk00DzDkkFW3U7k7zDUG9YFUDk7zD6T9YlUTs7zD0E841kTs7zD7nAAzszwDz022AAHzzzzz0UECS3zzzzzzzzzzzU"
}
WinGet, Win, List, ahk_exe Teams.exe
TeamsMainWinId := Teams_GetMainWindow()
TeamsMeetingWinId := PowerTools_RegRead("TeamsMeetingWinId")
WinCount := 0
Select := 0
Loop %Win% {
WinId := Win%A_Index%
If (WinId = TeamsMainWinId) { ; Exclude Main Teams Window
;WinGetTitle, Title, % "ahk_id " WinId
;MsgBox %Title%
Continue
}
WinGetTitle, Title, % "ahk_id " WinId
IfEqual, Title,, Continue
Title := StrReplace(Title," | Microsoft Teams","")
If RegExMatch(Title,"^[^\s]*\s?[^\s]*,[^\s]*\s?[^\s]*$") or RegExMatch(Title,"^[^\s]*\s?[^\s]*,[^\s]*\s?[^\s]*\([^\s\(\)]*\)$") ; Exclude windows with , in the title (Popped-out 1-1 chat) and max two words before , Name, Firstname
Continue
If RegExMatch(Title,"^Microsoft Teams Call in progress*") or RegExMatch(Title,"^Microsoft Teams Notification*") or RegExMatch(Title,"^Screen sharing toolbar*")
Continue
If (useFindText) {
; Exclude window with no Leave element
WinActivate, ahk_id %WinId%
If !(ok:=FindText(,,,, 0, 0, LeaveText,,0)) {
Continue
}
; Final check - exclude window with Resume element = On hold meetings
If (ok:=FindText(,,,, 0, 0, ResumeText,,0)) {
Continue
}
}
WinList .= ( (WinList<>"") ? "|" : "" ) Title " {" WinId "}"
WinCount++
; Select by default last meeting window used
If WinId = %TeamsMeetingWinId%
Select := WinCount
} ; End Loop
If (WinCount = 0)
return
If (WinCount = 1) { ; only one other window
RegExMatch(WinList,"\{([^}]*)\}$",WinId)
TeamsMeetingWinId := WinId1
PowerTools_RegWrite("TeamsMeetingWinId",TeamsMeetingWinId)
return TeamsMeetingWinId
}
If (restore)
WinActivate, ahk_id %curWinId%
LB := WinListBox("Teams: Meeting Window", "Select your current Teams Meeting Window:" , WinList, Select)
RegExMatch(LB,"\{([^}]*)\}$",WinId)
TeamsMeetingWinId := WinId1
PowerTools_RegWrite("TeamsMeetingWinId",TeamsMeetingWinId)
return TeamsMeetingWinId
} ; eofun

See also

Get Microsoft Teams Meeting Window using UIAutomation (latest solution)

Get Teams Window (older solution without FindText)