Skip to content

Instantly share code, notes, and snippets.

@natekford
Last active November 1, 2025 06:15
Show Gist options
  • Save natekford/57eb77234172275b14953fa4e038505a to your computer and use it in GitHub Desktop.
Save natekford/57eb77234172275b14953fa4e038505a to your computer and use it in GitHub Desktop.
Toggle mute via Windows for a microphone using AHK v2.
#Requires AutoHotkey v2+
#SingleInstance Force
global MIC := "FIFINE T669"
SetTray(SoundGetMute(, MIC))
SetTimer(CheckExes, 1000)
*F24::ToggleMuteAndNotify()
*F23::SetMuteAndNotify(1)
*F22::SetMuteAndNotify(0)
SetMuteAndNotify(value)
{
isMuted := SoundGetMute(, MIC)
SoundSetMute(value, , MIC)
if (isMuted != value)
{
Notify(value)
}
}
ToggleMuteAndNotify()
{
SoundSetMute(-1, , MIC)
Notify(SoundGetMute(, MIC))
}
SetTray(isMuted)
{
; 12 = not filled in W10 microphone, 13 = filled in W10 microphone
TraySetIcon("sndvolsso.dll", isMuted ? 12 : 13)
}
Notify(isMuted)
{
SetTray(isMuted)
SoundPlay(isMuted ? "C:\Windows\Media\Speech Off.wav" : "C:\Windows\Media\Speech On.wav")
ToolTip(isMuted ? "MUTED" : "UNMUTED")
SetTimer(() => ToolTip(), -1000)
}
CheckExes()
{
; some games interfere with hotkeys until the script is restarted
static ahk_start := A_TickCount
static exes := Map(
"RDR2", false,
"Condemned", false
)
for exe, isRunning in exes
{
; exe currently running
winExists := WinExist("ahk_exe " . exe . ".exe")
if (!isRunning && winExists)
{
; only reload if the exe is started after the script
if (A_TickCount > ahk_start + 5000)
{
Log(exe " is now running. Reloading script")
Reload()
}
; if it was running before the script, that's fine
else
{
Log(exe " was running before script launched; not reloading script.")
exes[exe] := true
}
}
; exe not running anymore, set back to false
else if (isRunning && !winExists)
{
Log(exe " is no longer running.")
exes[exe] := false
}
}
}
Log(text)
{
FileAppend(A_NowUTC ": " text "`n", "ToggleMuteMicrophone.log")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment