Use AutoHotKey to toggle default playback sound device

November 6, 2015 by Pat - Comments - - 3 min read

autohotkey_playbackDevicesIf you’re like me, then you have both speakers and headphones. Speakers are the primary of course, but when I want to block out the world, I use the headphones to zone in. I think it’s a little too cumbersome to go into the Sound applet > Playback Devices to change my default sound device every time I want to switch.

So with the combination of a few different sources, I’ve come up with a great way to quickly toggle your default sound device.

The first step is to get nircmd – this is a free tool from NirSoft. Download and save it to your %windir%\system32 folder. This is typically your c:\windows\system32 folder.

The second step is to get AutoHotKey. Download and install that. This software is what allows you to create new and custom hotkeys. I use it for a lot more than just changing my default sound playback device.

Then install this script below. I have it saved to My Documents. I also have a shortcut of this script in my startup folder so that the script is waiting and listening once I log in.

Here’s the script:

#Persistent			; This keeps the script running permanently.
#SingleInstance		; Only allows one instance of the script to run.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Win+A to change Audio Playback Device
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#a::
	toggle:=!toggle ; This toggles the variable between true/false
	if toggle
	{
		Run nircmd setdefaultsounddevice "Speakers"
		soundToggleBox("Speakers")
	}
	else
	{
		Run nircmd setdefaultsounddevice "Headphones"
		soundToggleBox("Headphones")
	}
Return

; Display sound toggle GUI
soundToggleBox(Device)
{
	IfWinExist, soundToggleWin
	{
		Gui, destroy
	}
	
	Gui, +ToolWindow -Caption +0x400000 +alwaysontop
	Gui, Add, text, x35 y8, Default sound: %Device%
	SysGet, screenx, 0
	SysGet, screeny, 1
	xpos:=screenx-275
	ypos:=screeny-100
	Gui, Show, NoActivate x%xpos% y%ypos% h30 w200, soundToggleWin
	
	SetTimer,soundToggleClose, 2000
}
soundToggleClose:
    SetTimer,soundToggleClose, off
    Gui, destroy
Return

Now all you need to do is find the name of your playback devices and substitute “Speakers” and “Headphones” for the 2 devices you want to switch between. To do that, right click on the Speaker icon in your system tray (down by the clock), select Playback devices, and you’ll see the device name in that window.

Launch or reload the AutoHotKey script. When you press Win+A, you should see a little popup box in the lower right corner of your screen telling you which playback device is the active one.

I chose Win+A because it was an available Win logo key hotkey combo, and the A was a good match for Audio. Feel free to change or modify the hotkey as you see fit. Here’s the full list of AutoHotKey combinations you can use (e.g. CTRL+Shift+A is ^+a::.)

# = Windows Logo Key
^ = CTRL Key
! = ALT Key
+ = Shift Key
< > = Used before one of the above to define left side key or right side key on the keyboard

Hope this helps!

Disclosure: Some of the links on this website are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.
Share this post: