Keyboard macro to change default audio device

Audioswitch (https://github.com/sirWest/AudioSwitch) allows you to quickly change default audio device (with a click on a tray icon), has hotkey support, shows volume levels on click, and allows custom colours for the tray icon to show which device is in use. Plus, it's open source. So if you don't like it, fork off ... (to your heart's delight).

A second answer is Volume2 (https://github.com/irzyxa/Volume2), another free (but not open source) piece of software. You can set hotkeys to change devices. (You can also, as has been pointed out in another answer, change by othermeans, but this was not what OP asked so I didn't get into it.) It has now replaced, for me, AudioSwitch, mostly because it allows more flexible volume adjustments (which again wasn't OP's question).

A third answer is Audio Switcher. http://audioswit.ch/er. It also allows changing on click, and hotkeys. It does not allow volume changing with the mouse, at least in version 1.


Based off of this article.

  1. Download and install AutoHotkey.

  2. Open your sound control panel. This can also be done through running mmsys.cpl through the start menu search or the run dialog.

  3. Note how far down the list your desired options are. In the following image, the HDMI Output is item 1 and the current default Speakers is item 4.

    Screenshot of sound control panel

  4. Modify the following script. F6 and F7 represent the activation key (F6 and F7) (the * means this hotkey applies even when modifiers such as Ctrl are pressed). The {Down #} command indicates how far down the list to go. From your screenshots, you want {Down 3} for Speakers and {Down 4} for Headset. If you add or remove audio devices, or show/hide disabled items, the number will change.

    *F6::
        Run, mmsys.cpl
        WinWait,Sound
        ControlSend,SysListView321,{Down 3}
        ControlClick,&Set Default
        ControlClick,OK
        return
    
    *F7::
        Run, mmsys.cpl
        WinWait,Sound
        ControlSend,SysListView321,{Down 4}
        ControlClick,&Set Default
        ControlClick,OK
        return
    
  5. Run the script. You can set the script to run at startup if you'd like.


The reason I call this a 'hack' is the script actually opens the control panel (a GUI window). Ideally, this could be done through the command line, by specifying the sound device's GUID.

There's apparently a program with a CLI to switch sound devices. You supply the same number in the list, which makes me think it's not much different from the AutoHotkey 'hack' here. In any case, something like AHK would be required to bind it to a hotkey.


Auto Hotkey script as a toggle using the scroll-lock key.

take out items by disabling them (such as hdmi on your lcd's etc)

I prefer this as I only need to change my sound output if it is set to the incorrect selection. Hitting scroll-lock switches me to the correct one. Very useful if i am already loading a game and realize it is wrong. Most games need to be restarted if you want to change the sound output.

ScrollLock:: 
  toggle:=!toggle ;toggles up and down states. 
  Run, mmsys.cpl 
  WinWait,Sound ; Change "Sound" to the name of the window in your local language 
  if toggle
    ControlSend,SysListView321,{Down 1} ; This number selects the matching audio device in the list, change it accordingly 
  Else
    ControlSend,SysListView321,{Down 2} ; This number selects the matching audio device in the list, change it accordingly 
  ControlClick,&Set Default ; Change "&Set Default" to the name of the button in your local language 
  ControlClick,OK 
return