Sending keystrokes to Microsoft Teams running in the background

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
csongorvarga
Posts: 1
Joined: 15 Sep 2022, 16:26

Sending keystrokes to Microsoft Teams running in the background

Post by csongorvarga » 15 Sep 2022, 16:43

Hi All,

I have a macro keyboard and I want to configure some buttons to send Mute/UnMute, Camera On/Off, Leave meeting, etc hotkeys to my running Teams Meeting window. In most cases when I am in a meeting, I am checking my emails, updating a document, so Teams is usually not the active window.

I want to do the following: my macro keyboard send Ctrl+Alt+1 and when this happens I want to send a Ctrl+Shift+M to Teams. Ctrl+Alt+1 is just an example I will use a combination which is not used in any of my usual apps.

I noticed that when I am in a call, Microsoft Teams have a main window, but the meeting opens in another window. The window title is dynamic in both, so I cannot use that. Both of them are ahk_class Chrome_WidgetWin_1, ahk_exe Teams.exe. But at least I noticed that window that I used the last responds to ahk_exe Teams.exe. So as long as I used the Meeting window last, I can switch to hat using ahk_exe Teams.exe.

So far I crated this script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
^+1::
WinActivate, ahk_exe Teams.exe
ControlSend, , ^+M, ahk_exe Teams.exe
return
Unless I WinActivate first, the ControlSend is not working. Well, I guess ControlSend with the ahk_exe Teams.exe is not working. But this is how I understand this from the help, the akh_exe needs to be used in the third parameter. Or am I doing something wrong?

If WinActivate is the only option, is there a way of storing the current active window and switching back to my previous window after ControlSend?


[Mod edit: Topic was moved from 'Scripts and Functions'.]


Post Reply

Return to “Ask for Help (v1)”