Skip to content

Instantly share code, notes, and snippets.

@lawkaita
lawkaita / SoundGetDefaultDeviceIndex.ahk
Created April 18, 2024 17:38
Get the device index of the default playback or capture device, to be used with ahk Sound Functions.
#Requires AutoHotkey v2
SoundGetDefaultDeviceIndex(desc := 'playback') {
; based on this post in the AutoHotkey discord
; https://discord.com/channels/115993023636176902/1175025590936543283/1175136154132156526
; and this line in the AutoHotkey source code
; https://github.com/AutoHotkey/AutoHotkey/blob/59f219a111a34b21529c7acf5026e11650a06fbc/source/lib/sound.cpp#L96
static CLSID_MMDeviceEnumerator := "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
, IID_IMMDeviceEnumerator := "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
, S_OK := 0
, VT_UNKNOWN := 0xD