Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Windows 7, Logitech G110 keyboard

2 audio devices (headphones and speakers)

I am hoping to find a quick way to macro a key to switch to headphones, and a key to switch to speakers.

Anyone have a good program or anything of that nature?

EDIT: Using AHK to try and get this task working as hoped is sadly not doing the trick. I have included a screenshot of my audio set, as well as a screenshot of my script as it sits now. Sound setup Script

I have also tried to uncheck "show disabled devices" and modified the script to be Down 1, and Up 1 respectively. It will work for one device, but it refuses to switch to the secondary.

share|improve this question
Autohotkey hacks: this article or the second post here. If someone has enough time to write one of those up into a full answer, feel free. –  Bob May 19 '12 at 5:32
Followed the instructions in those 2 links, still no luck sadly, AHK doesnt seem to like my audio selection choices, and constantly defaults to my Speakers instead of switching between headphones and speakers –  francisswest May 19 '12 at 5:57
Well, what are your choices? How about a screenshot, or at least a list? –  Bob May 19 '12 at 6:06
@Bob - Sorry about that, I have edited the post with the info requested. –  francisswest May 19 '12 at 18:40

3 Answers 3

up vote 2 down vote accepted

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.

        Run, mmsys.cpl
        ControlSend,SysListView321,{Down 3}
        ControlClick,&Set Default
        Run, mmsys.cpl
        ControlSend,SysListView321,{Down 4}
        ControlClick,&Set Default
  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.

share|improve this answer
You sir, are fantastic. Thank you for the assistance. It is now a functional script! Flagged as the answer, and upvoted. Much appreciated! –  francisswest May 19 '12 at 21:23
If you just want to toggle between two outputs, here is an updated script to do that. –  MBraedley Nov 22 '12 at 1:10

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.

  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 
    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 
share|improve this answer

The following script allows you to create a shortcut on the desktop that toggles between two devices. The script may need modifying for the correct device names and uses nircmd which needs downloading. A hotkey for the shortcut could be used. Mainly posting here for a record. The icon and script name toggle to reflect the current device. It is possible for them to get out of sync as there is no check(need a command to get the current default device).

' Set the audio device names to use(Speakers and Headphones/PC Headphones. Fixup dir to nircmdc

Const USER_DESKTOP = &h10&
Const nircmd = "D:\Windows\Commands\Nircmdc"
Const Device1 = "Speakers"
Const Device1Name = "Speakers"
Const Device2 = "PC Headphones"
Const Device2Name = "Headphones"

Set ws = CreateObject("Wscript.Shell")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(USER_DESKTOP)
Set objFolderItem = objFolder.ParseName(Device2Name +".lnk")

if isNull(objFolderItem) or IsEmpty(objFolderItem) or (objFolderItem is Nothing) then
    Set objFolderItem = objFolder.ParseName(Device1Name + ".lnk")
    if isNull(objFolderItem) or IsEmpty(objFolderItem) or (objFolderItem is Nothing) then       
        ' Creates shortcut on desktop to toggle between devices and sets the default to Speakers
        Set oMyShortcut = ws.CreateShortcut(objFolder.Self.Path + "\"+Device1Name+".lnk")
        oMyShortcut.WindowStyle = 0
        OMyShortcut.TargetPath = WScript.ScriptFullName
        'oMyShortCut.Hotkey = "ALT+CTRL+S"
        oMyShortcut.IconLocation = "C:\Windows\System32\mmres.dll, 0"

        ws.run nircmd + " setdefaultsounddevice """+Device1+""" 0", 0
        ws.run nircmd + " setdefaultsounddevice """+Device1+""" 1", 0
        ws.run nircmd + " setdefaultsounddevice """+Device1+""" 2", 0
        msgbox "Desktop link created for """+Device1+""". "+Device1+" set as default!", 0, "Error"
        ' Speaker was set, make headphones
        Set objShellLink = objFolderItem.GetLink
        objShellLink.SetIconLocation "C:\Windows\System32\mmres.dll", 2
        objFolderItem.Name = Device2Name

        ws.run nircmd + " setdefaultsounddevice """+Device2+""" 0", 0
        ws.run nircmd + " setdefaultsounddevice """+Device2+""" 1", 0
        ws.run nircmd + " setdefaultsounddevice """+Device2+""" 2", 0

    end if
    ' Headphones was set, make speakers
    Set objShellLink = objFolderItem.GetLink    
    objShellLink.SetIconLocation "C:\Windows\System32\mmres.dll", 0
    objFolderItem.Name = "Speakers"

    ws.run nircmd + " setdefaultsounddevice """+Device1Name+""" 0", 0
    ws.run nircmd + " setdefaultsounddevice """+Device1Name+""" 1", 0
    ws.run nircmd + " setdefaultsounddevice """+Device1Name+""" 2", 0
end if
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.