Skip to content

Instantly share code, notes, and snippets.

@hattorix
Last active March 1, 2022 16:50
Show Gist options
  • Save hattorix/0d4a8523c59074327c4c93840fa957ee to your computer and use it in GitHub Desktop.
Save hattorix/0d4a8523c59074327c4c93840fa957ee to your computer and use it in GitHub Desktop.
Toggle default communication device in AutoHotkey
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force
#include %A_ScriptDir%/VA.ahk
GetDefaultCaptureCommDevice() {
if (r := DllCall("ole32\CoCreateInstance"
, "ptr", VA_GUID(CLSID_MMDeviceEnumerator, "{BCDE0395-E52F-467C-8E3D-C4579291692E}")
, "ptr", 0, "uint", 21
, "ptr", VA_GUID(IID_IMMDeviceEnumerator, "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
, "ptr*", deviceEnumerator)) != 0
return 0
device := 0
; deviceEnumerator->GetDefaultAudioEndpoint("eCapture", "eCommunications", [out] device)
DllCall(NumGet(NumGet(deviceEnumerator+0)+4*A_PtrSize), "ptr",deviceEnumerator, "uint",1, "uint",2, "ptr*",device)
ObjRelease(deviceEnumerator)
return device
}
ToggleMicMute() {
if ! device := GetDefaultCaptureCommDevice()
return
VA_IMMDevice_Activate(device, "{5CDF2C82-841E-4546-9722-0CF74078229A}", 23, 0, endpointVolume)
VA_IAudioEndpointVolume_GetMute(endpointVolume, mute)
if (mute = 0) {
VA_IAudioEndpointVolume_SetMute(endpointVolume, 1)
SoundPlay, sounds\mic_off.wav
} else {
VA_IAudioEndpointVolume_SetMute(endpointVolume, 0)
SoundPlay, sounds\mic_on.wav
}
ObjRelease(device)
ObjRelease(endpointVolume)
}
^F12::ToggleMicMute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment