So in about 10 minutes, I had it working. But enough with the background story - let's check out the code!
Code: Select all
/**
* Sets the default audio playback device
* @param[in] {int} n - A number from 1 to the total number of devices you have (3 on my machine)
* @remarks - Tested on Win10 x64 with AHK 1.1.25.01 Unicode x86
*/
SetSound(n)
{
; Because this is a control panel "applet" and not a regular program, the Run call is pretty strange, but it works
Run, rundll32.exe shell32.dll`,Control_RunDLL mmsys.cpl
; For the same reason, WinActivate, WinWaitActive etc. don't work. So:
Sleep 500
; But once the window is up, it's just straightforward Send calls the rest of the way.
Send {Tab 4}{Down}
Loop % n - 1
Send {Down}
Send {Tab 2}{Space}{Escape}
}
; And test it - worked for me
^1::SetSound(1)
^2::SetSound(2)
^3::SetSound(3)