This is the registry address that contains changing level 1 and level 2 QWORD values. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render
I read that the default device has the highest number on the list and counts up with each change. Is there a way compare that information in Realtime (a loop?), and identify the the device using AHK?
Here's my code.
Code: Select all
bthpKey := "HKLM\Software\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{7e51e24c-1691-4d95-9a39-4826002a85ed}\Properties"
bthpVal := "{9c119480-ddc2-4954-a150-5bd240d454ad},1"
QuesthpKey := "HKEY_CURRENT_USER\SOFTWARE\AHKRegWrite\DefaultAudio"
QuesthpVal := "Headphones"
bthpstatus := 1
loop {
RegRead, btHeadphones, %bthpKey%, %bthpVal%
If (btHeadphones) {
bthp_connect := true
if bthpstatus {
bthpstatus := 0
Run "D:\My Tools\AHK\Repo\Audio\Headphones.ahk"
}
} else {
bthp_connect := false
bthpstatus := 1
}
RegRead, QuestHeadphones, %QuesthpKey%, %QuesthpVal%
If (ErrorLevel) {
qhp_connect := false
} else {
qhp_connect := true
}
}
#If WinActive("ahk_class MPC-BE") || WinActive("ahk_class {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}")
WheelUp::
if (bthp_connect) or (qhp_connect) {
soundset, +5
} else {
run, "D:\My Tools\Shortcuts\Receiver Volume Up.lnk"
}
return
WheelDown::
if (bthp_connect) or (qhp_connect) {
soundset, -5
} else {
run, "D:\My Tools\Shortcuts\Receiver Volume Down.lnk"
}
return
#If
WheelRight::
if (bthp_connect) or (qhp_connect) {
soundset, +5
} else {
run, "D:\My Tools\Shortcuts\Receiver Volume Up.lnk"
}
return
WheelLeft::
if (bthp_connect) or (qhp_connect) {
soundset, -5
} else {
run, "D:\My Tools\Shortcuts\Receiver Volume Down.lnk"
}
return
Code: Select all
DetectHiddenWindows, On
Run "D:\My Tools\System Tools\NirCMD\nircmdc.exe" "setdefaultsounddevice" "Oculus" , , Hide
RunWait, taskkill /f /t /im voicemeeter.exe
RegDelete, HKEY_CURRENT_USER\Software\AHKRegWrite\DefaultAudio, Receiver
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\AHKRegWrite\DefaultAudio, Headphones
https://stackoverflow.com/questions/59393574/how-to-identify-the-default-audio-device-in-powershell