Building a physical Microsoft Teams (or Zoom or Skype) mute button

While working from home I, like millions of others, am stuck in constant conference calls. After almost a year you would think that we all would have this under control. But no, not a chance. It takes only four simple words halfway through a lengthy explanation to remind us we learn very, very slowly… “You are on mute”.

You're muted

This constant struggle to remember to click one single button when I want to speak led to this, making a physical switch to mute and unmute myself when using Microsoft Teams.

As a bonus, this was one of those rare projects where you get something really useful with very little effort. Once I had the correct components it probably took less than 15 minutes to have something that works. Score!

 

How does it work?

This is a quick build and is entirely based around keyboard shortcuts in Windows. Within Teams the microphone can be muted using the <Ctrl> + <Shift> + <M> keyboard shortcut and the switch I made just emulates these keypresses.

The basis for this project is the Keyboard Arduino library. This library “enables 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port”. With this library and a 32u4 micro based Arduino we can send the required shortcut whenever we read a state change on one of the Arduino’s digital inputs.

 

The build

What is needed?

  • A 32u4 or SAMD based Arduino. I went for a Pro Micro ATmega32u4 from Amazon which is compatible with the Arduino Leonardo.
    Pro Micro ATmega32u4 Arduino Leonardo compatible
  • Any switch. I selected a latching toggle switch as it has a satisfying click when toggled.

Nothing else is required. I added a couple of LEDs just in case I need them in the future.

Putting everything together

Some quick soldering is required to connect the switch to an input pin. As mentioned, I added some unnecessary LEDs.

The Pro Micro pinouts used are:

  • A0 (pin 18) – Toggle switch
  • A6 (pin 4) – LED 1
  • A8 (pin 8) – LED 2
Mute button Arduino connection diagram
Simple connection diagram for the Teams mute button

And here is everything all wired up and connected with some bad soldering. A simple box was 3D-printed to house everything.

Mute button components soldered
Everything (badly) soldered together

 

Teams mute button in 3D-printed box
Assembly in the 3D-printed housing

 

Completed Teams mute button assembled with LEDs and switch
Final assembly with superfluos LEDs

 

Arduino Code

The Arduino code reads the status of the switch. If the switch changes it sends the necessary key combination to the PC. For this to work Teams has to have focus in Windows otherwise the <CTRL> + <SHIFT> + <M> shortcut command for whichever program you are in will be run.

If you use a momentary switch it is a good idea to code in a switch debounce to avoid flickering and sending the command multiple times.

#include <Keyboard.h>

//Global variables
int currentState;
int previousState;

//MS Teams mute and unmute shortcut is the same. This means a momentary switch is better to use

void setup()
{
 pinMode(A0, INPUT_PULLUP);     //pin A0 is switch input.
 pinMode(4, OUTPUT);            //pin 4 is an digital output for a LED
 pinMode(8, OUTPUT);            //pin 8 is an digital output for a LED

 //Start Keyboard
 Keyboard.begin();

 //Set LEDs initial states
 digitalWrite(4, LOW);
 digitalWrite(8, HIGH);
}

void loop()
{
  //Read switch
  currentState = digitalRead(A0);

//Check swtich has changed from off to on to Mute
  if (currentState != previousState)
  {
    sendMuteShortcut();

    //Flip LEDs
    digitalWrite(4, currentState);
    digitalWrite(8, !currentState);

    //Remember previous tate
    previousState = currentState;
  }
  else
  {
    //do nothing
  }
}

void sendMuteShortcut()
{
  //Send Team's keyboard shortcut to mute
  Keyboard.press(KEY_LEFT_CTRL);    //Press left control
  Keyboard.press(KEY_LEFT_SHIFT);   //Press left shift
  Keyboard.press('m');              //And press 'm' to mute
  delay(100);                       //Wait 100ms
  Keyboard.releaseAll();            //Release all keys
}


Making it better

As mentioned, the code above, and therefor the switch, only does what it is supposed to if Microsoft Teams has focus on your computer. What we really need is the ability to mute and unmute regardless of the window that has focus. To enable this, we need to run a simple script on the PC that will give the Teams window focus first and then execute the mute keyboard shortcut.

To trigger the script, we will send a different unique keyboard shortcut when the switch is flipped. To ensure maximum compatibility make sure to select a keyboard shortcut that is not used anywhere in Windows. I have gone for <Ctrl> + <Shift> + <0> with the section of Arduino code now changed to send this instead of <Ctrl> + <Shift> + <M>.

  //Send keyboard shortcut to run AutoHotKeyScript
  Keyboard.press(KEY_LEFT_CTRL);    //Press left control
  Keyboard.press(KEY_LEFT_SHIFT);   //Press left shift
  Keyboard.press('0');              //And press '0' to run script
  delay(100);                       //Wait 100ms
  Keyboard.releaseAll();            //Release all keys

On the Windows PC the script is managed by a small application called AutoHotKey. Once AutoHotKey is installed you just right-click on the desktop and go to New > AutoHotKey Script.

AutoHotKey Teams mute script
How to create new AutoHotKey script

The newly created file is then edited to specify what it should do. The file can be edited by your favourite text editor, in my case NotePad++. AutoHotKey uses its own scripting language. This is very well documented and part of the help file accompanying the AutoHotKey installation. Many people have also already written AutoHotKey scripts for Teams. For our purpose the script looks like this.

^+0::
WinGet, id, list, ahk_exe Teams.exe ;get IDs for all teams windows
Loop, %id% ;Loop through IDs of all teams windows
{
this_ID := id%A_Index%
WinGetTitle, Title, ahk_id %this_ID% ;get the title of the current window
If Title <> Microsoft Teams Notification ;make sure title is not the notification
{
If Title <> ;screen sharing win uses null title, make sure the win does not have a null title
{
WinActivate, ahk_id %this_ID% ;This should be the correct win, activate it
Send, ^+M ;send ctrl,shift,m shortcut
break ;There are two teams windows, the main win and the meeting win, break the loop so that the mute commmand doesnt get sent twice
}
}
}

The script activates when <CTRL> + <SHIFT> + <0> is pressed, or in our case sent from the Arduino. It then gets the IDs for all the windows associated with Teams.exe and loop through them until finding the first windows that is not a Teams notification or screen sharing window. This window must either be the current meeting or the main window. The window is activated, gaining focus, and the mute keyboard shortcut is sent.

To activate the script, double click on the newly created .ahk file.

 

What about other applications?

The setup can be adapted for any application or purpose. To toggle mute in Skype the keyboard shortcut is <CTRL> + <M>. To repurpose the switch for Skype we only need to update the AutoHotKey script to look for a Skype windows instead and send <CTRL> + <M>.

The Arduino setup can also be further extended to support multiple switches each sending it’s own key combination. This can be used to create a set of shortcut buttons for use in photo/video editing, or to have dedicated buttons to launch your favourite applications. It can also be used in games, such as Counter-Strike, to send specific key combinations to buy your favourite weapon layout.

But first, back to the meetings :-/

Leave a Reply