Hacking the Teams Local API: How I Built a “Blind” Mute Button with AutoHotkey & Python

As a developer, few things are more frustrating than “flaky” software behavior. We’ve all been there: you’re in a Teams meeting, multitasking on another monitor, and suddenly need to cough or answer a question. You hit the global mute shortcut (Ctrl+Shift+M), but… nothing happens. Because Teams wasn’t in focus, the keystroke got swallowed by your IDE or browser.

I got tired of scrambling to find the Teams window just to toggle my microphone. I didn’t want a “hacky” solution that tries to bring the window to the front; I wanted a reliable, background-capable, state-aware toggle.

So, I built one.

The Discovery: It’s All About WebSockets

I noticed that hardware like the Elgato Stream Deck could control Teams reliably without focus. After some digging, I realized Microsoft exposes a Local Third-Party API via WebSockets on localhost:8124. This is the “proper” engineering path—don’t emulate user input; talk to the backend.

The challenge? The API requires a specific handshake and token authentication that is tricky to handle natively in simpler scripting languages.

The Stack: AHK + Python

To solve this, I combined two tools:

  1. AutoHotkey v2: The perfect tool for the “frontend.” It handles the global keyboard/mouse hooks (listening for my specific keybind) with near-zero latency.
  2. Python: The heavy lifter for the “backend.” It handles the WebSocket connection, manages the authentication token with Teams, and sends the JSON payloads.

How It Works

When I press my hotkey (mapped to a side button on my mouse), AHK triggers the Python script in the background. The script:

  1. Checks for an existing auth token.
  2. Opens a WebSocket connection to Teams.
  3. Sends the toggle-mute command.
  4. Updates the actual mute state in the Teams UI instantly.

The result is a “blind” mute button that works 100% of the time, regardless of what window I’m working in. No more “Am I muted?” anxiety.

Open Source

If you want to use this for your own setup (it’s great for macropads, foot pedals, or just a reliable F-key), I’ve open-sourced the code on GitHub. It handles the token setup automatically, so it’s pretty much plug-and-play.

Check out the repo here: https://github.com/Russell-KV4S/teams-local-mute

Let me know if you give it a try!