How to get the Microsoft Teams active meeting window with AutoHotkey?

Viewed 1088

In the Microsoft Teams Windows Client I would like to be able to identify with AutoHotkey the current active meeting window. Consider that you can have several Teams window opened (popped-out chats, main window, several meeting windows with some on hold,...)

(Background: I want to do this to be able to send meeting specific actions hotkeys.)

3 Answers

I have come to another approach based on FindText to exclude any user prompt. It check in the Teams windows if a UI Element like Leave and Resume are available to 100% exclude the wrong window.

See detailed explanation in this post: https://tdalon.blogspot.com/2021/04/ahk-get-teams-meeting-window.html with screencast. And here the code in gist: https://gist.github.com/tdalon/d376a2ac395a41c5453904222cbcb529

Extract below:

Teams_GetMeetingWindow(useFindText:="" , restore := True){
; See implementation explanations here: 
;   https://tdalon.blogspot.com/2021/04/ahk-get-teams-meeting-window.html
;   https://tdalon.blogspot.com/2020/10/get-teams-window-ahk.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

I have tried to find it out by the Window Title, but Teams does not name Meeting windows in a particular way.

I could find with AccViewer that the Main Team Window has its name ending with "| Microsoft Teams, Main Window". So at least I can exclude this one.

Here is the best solution I have come to. But it requires the user to confirm which window is the current meeting window (if not obvious).

The code can be found in this Gist: https://gist.github.com/tdalon/87590637e43479c90f355be90aff3842#file-teams_getmeetingwindow-ahk

Related