Hotkey to Switch Audio Devices

hotkey-switch-audio-devices

I switch back and forth between my headphones and computer speakers at work a lot. So I decided it was time to figure out a hotkey to do this. My coworker told me about a program called AutoHotkey, and combined with a small file it does everything I want it to. In this example below I am using F6 to switch to my computers and F7 to switch to my Logitech headphones. Also, I am running Windows 7 x64. The following tutorial should work fine on Windows 7 x32 and Windows 7 x64.

Audio Devices Hotkey

Step 1

Download and install AutoHotkey. (download link)

Step 2

During the installation, there is a x32 and x64 bit version. In this example, I am using the x64 bit version. The x32 should work fine as well. The new few screens just accept the default and click Next.

autohotkey x32 and x64

Step 3

Before launching the program you will need to download our customized AutoHotkey file. Right click and choose “Save Link As” on this file: AutoHotkey.ahk. Save the file in the root of your “My Document” folder. This is where AutoHotkey will look when it launches.

autohotkey.ahk

You can also copy the contents of the .ahk file below:

*F6::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down 4}
    ControlClick,&Set Default
    ControlClick,OK
    return

*F7::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down 3}
    ControlClick,&Set Default
    ControlClick,OK
    return

Step 4

Now you need to find what order your audio devices are in. On the bottom right of your taskbar, right click on the speaker icon and click “Playback devices.”

Playback Devices

Step 5

You need to make a note of which order they are in before we go edit the AutoHotkey.ahk file. Notice that in my example, my computer speakers are 3 down from the top and my Logitech headphones are 4 down from the top.

Speakers

Step 6

Now go and open the AutoHotkey.ahk file, that is in your My Documents folder, with Notepad. You will notice I set the down number in the file to match the order of my audio device. Also, you can change the function key to something else if you like.

autohotkey

Step 7

Now launch AutoHotkey from your program files, and it will run on your taskbar.

autohotkey

Step 8

I recommend reloading the script. Right click on AutoHotKey running in your taskbar and select “Reload this script.”

autohotkey - reload script

Now you can test your hotkey by pressing your function keys. If you have everything setup correctly this will now toggle between your audio devices with one press of a button! :)

User Suggestion

French noob also recommended this software. We tried it and it also works great! http://soundswitch.codeplex.com/

Incoming search terms:

  • windows 8 switch audio device
  • windows 8 sound switch
  • audio switcher windows 8
  • windows 8 1 audio switcher
  • Switch Audio Output Windows 8
  • Fred P.

    Thanks this was exactly what I was looking for. I have a 3 screen set up. 2 monitors on my desk and a HD TV. The main computer monitor and HD TV are clones using an HDMI splitter. I use the TV when I’m laying on the couch or watching youtube/movies from the computer. It was a pain having to always go into sound options and switch form computer speakers and TV speakers constantly. Now all I do is hit a button and it’s done! Tip for others: After you change the code be sure to right click the program and select reload script! :D

    • http://www.theitbros.com Brian Jackson

      Thanks! Yes, I have been using this non-stop at work to switch between my primary speakers and headphones :) Actually saves a lot of time if you add up all the times you have to switch. I edited the post and added the ‘reload script’ part. I forgot to do that :) Thanks.

  • Hannes

    Hi for some reason this script only opens the sound device selection window. when i press either hotkey. i followed all steps i only have 2 sound devices so i set it to 1 and 2. what is wrong?

    • Hannes

      also is there a way to set 1 toggle key instead of two hotkeys?

      • Hannes

        OK figured it out.. after poking around a bit. i had to change

        WinWait,Sound to WinWait,Ljud
        and
        ControlClick,&Set Default to ControlClick,&Standard

        which it is int swedish version of windows.

        but a toggle would still be nice :)

        • Dawid Dahl

          Tack för hjälpen där, Hannes! Nu fungerar det!

          • http://www.theitbros.com Brian Jackson

            Your very welcome… seeing from Google translator… I’m assuming you said the following?? “Thanks for the help there, Hannes! Now it works!”

  • Necromas

    How can I modify this to change the default recording device?

    • http://xenogamers.org McNeo

      *F8::
      Run, mmsys.cpl
      WinWait,Sound
      Send {TAB 3}{RIGHT}
      ControlSend,SysListView321,{Down 1}
      ControlClick,&Set Default
      ControlClick,OK
      return

      Follow the directions in the original how-to to change the hotkey and determine your recording device number.

      Protip: Change playback and recording devices in one swoop
      *F6::
      Run, mmsys.cpl
      WinWait,Sound
      ControlSend,SysListView321,{Down 3}
      ControlClick,&Set Default
      ControlClick,OK
      Run, mmsys.cpl
      WinWait,Sound
      Send {TAB 3}{RIGHT}
      ControlSend,SysListView321,{Down 1}
      ControlClick,&Set Default
      ControlClick,OK
      return

      *F7::
      Run, mmsys.cpl
      WinWait,Sound
      ControlSend,SysListView321,{Down 2}
      ControlClick,&Set Default
      ControlClick,OK
      Run, mmsys.cpl
      WinWait,Sound
      Send {TAB 3}{RIGHT}
      ControlSend,SysListView321,{Down 2}
      ControlClick,&Set Default
      ControlClick,OK
      return

    • Zude

      I used this to disable/enable my mic, but you can modify to change your default recording device:

      #z::
      Run, mmsys.cpl
      WinWaitActive,Sound ; Wait for window to appear
      Control,TabRight, 1, SysTabControl321 ; Select second tab
      Sleep 10 ; Wait for tab, modify as needed
      ControlSend,SysListView321, {Down 1} ; In the list of devices, select the mic to disable
      Send {Shift}+{f10} ; Right-click
      Sleep, 20 ; Wait for menu, modify as needed
      SendPlay {Down} ; Arrow down to Disable/Enable
      Send {Enter} ; Select
      ;ControlClick OK ; Exit

      Hope it helps,

      • http://www.theitbros.com Brian Jackson

        Great comment, thanks for the tip!

  • Daan

    Like Hannes already found out, the script as it is here only works for english versions of windows.
    So for everyone who hadn’t figured it out form the post, the hints for how to make this work for any language version of windows are in the script.

    1; after WinWait, the word should be the same as the name of your audio panel(on top it says the name: Sound in English, Ljud in Swedish and in my case, Geluid in Dutch)
    2; after ControlClick, the text should be the same as the center button on the audio panel, the one to set the dafault ( Set Default in English, Standard in English, Als standaard instellen in Dutch)

    This should get you to figure it out in any language, and remember to pay attention to capitals.

  • UNKNOWN TO MAN

    just wanna say thanks!! this is really gonna make switching sound devices easier

  • Nils

    Great Stuff, after some enhancements from Hannes June 15 it’s working perfect!
    Also I agree with Hannes – to toggle the source would be really nice ;-)

    • Nils

      ..got no Idea how to do this (to toggle sources) ?!

  • Hazel

    Many thanks, just what wanted works a treat.

  • shajith

    It is working fine, but my sound device is keep changing one to another automatically so when i open windows media player sound is discontinued in second interval. Try disabling the second digital audio device but result is same, pls help me

  • Dylan

    Hi, thx for this, it’s really helpfull, i was just wondering if there is also a way to get not altabbed when playing a game for example and you pres f6 or f7?

  • inhumanist

    For all non-english windows users; you have to change the file according to the following pattern:
    ControlClick,&***
    where *** is what the drop-down button in sound devices says when a non-standard device is selected,
    WinWait,#
    where # is the term that is used instead of “sound” in your windows version.

    For example, in german Win7 it’s
    WinWait,Sound
    ControlClick,&Als Standard

    • p01i

      Skrypt zmieniający automatycznie domyślne urządzenie audio w win7:
      For Polish UI working code is:

      *F6::
      Run, mmsys.cpl
      WinWait,Dźwięk
      ControlSend,SysListView321,{Down 1}
      ControlClick,&Ustaw domyślne
      ControlClick,OK
      return

      *F7::
      Run, mmsys.cpl
      WinWait,Dźwięk
      ControlSend,SysListView321,{Down 2}
      ControlClick,&Ustaw domyślne
      ControlClick,OK
      return

      • misiektoja

        Dzięki, na Windows 7 działa, ale na Windows 8 wymagana jest mała
        zmiana (ze względu na domyślne urządzenie do odtwarzania i
        komunikacyjne):

        *F6::
        Run, mmsys.cpl
        WinWait,Dźwięk
        ControlSend,SysListView321,{Down 1}
        ControlClick,&Ustaw domyślne
        ControlSend,SysListView321,{Down 1}
        ControlClick,OK
        return

        *F7::
        Run, mmsys.cpl
        WinWait,Dźwięk
        ControlSend,SysListView321,{Down 2}
        ControlClick,&Ustaw domyślne
        ControlSend,SysListView321,{Down 1}
        ControlClick,OK
        return

  • Dan

    Thank you so much! exactly what i was looking for, only wish I came across this article sooner

    • http://www.theitbros.com Brian Jackson

      Glad it helped!

  • Asura23

    I love you man! I just bought G930 headset and was facing this same problem,…big thanks!

    • http://www.theitbros.com Brian Jackson

      We love the G930s :) !

  • Gabe

    Thanks a bunch for this. So much easier with this script !

  • George

    SOmehow it doesn`t work for me i follow the steps excactly as you say i did it again but nothing when i press the fuction keys it just open the panel of the playback devices and that all the command stops there

    • George

      i guess i have to change the commands in my language but still nothing does the script understands the Greek characters?

  • dajolt

    This has also been discussed in the Autohotkey Forums and there’s a solution at the end that avoids using the GUI.

    http://www.autohotkey.com/board/topic/2306-changing-default-audio-device/

    • http://www.theitbros.com Brian Jackson

      Great! Thanks for the tip. I will give that a try and probably update the post.

  • neronix17

    A way to toggle this would be fantastic, is there a way to have it check if one is currently active and then switch to the one which is not active? Out of two chosen devices of course, if this can be done it would help me greatly as I’d like to only have one macro key taken up with this.

    • http://theitbros.com/ Brian Jackson

      I don’t know of a way to automatically toggle this. Check on the autohotkey.com forums… they might have some new updates from someone that could do this.

  • Guigur

    Even simpler is to use FastKeys, It handles this very well plu has tons of other features – you can even import full AHK scripts. Check fastkeys.vze.com.

    • http://theitbros.com/ Brian Jackson

      Thank you for your comment! I will have to check that out.

  • http://www.facebook.com/dwhettam Dan Whettam

    Would be useful if you could type it out so I could copy and paste it in to avoids typos and misreading etc. Thanks.

    • http://theitbros.com/ Brian Jackson

      Thank you for your comment, I have pasted the contents of the .ahk file above now in Step 3.

  • French noob

    It could be a good solution but it didn’t work with my french version of windows so i kept up searching for a solution and i found this http://soundswitch.codeplex.com/ that works perfectly.

    I dont mean that it is better than the job you did, but since it is the first page i found on google, it might help people for whos your solution dont work, but thanks anyway :-/

    • http://theitbros.com/ Brian Jackson

      SoundSwitch didn’t exist when we originally wrote this. I just gave that a try and it works great! We just edited our article and put your suggestion at the bottom of the post. Thanks for your comment!

    • Paulo

      Thank you, works great!

      • http://theitbros.com/ Brian Jackson

        Great, glad it helped!

  • Paulo

    I Brian!

    I’ve been trying for 2h now to make this to work and without success…

    My default windows language is “Portuguese”.

    I’ved tried everything i could think off…

    The portuguese word for “sound” is “Som”.
    Thanks

  • misiektoja

    For Windows 8 small change is required (because of two default output devices, for playback and communication):

    *F6::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down 4}
    ControlClick,&Set Default
    ControlSend,SysListView321,{Down 1}
    ControlClick,OK
    return

    *F7::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down 3}
    ControlClick,&Set Default
    ControlSend,SysListView321,{Down 1}
    ControlClick,OK
    return

    • http://theitbros.com/ Brian Jackson

      Great. Thank you for sharing with our readers.

  • jfflee

    Hi! This script has worked for me beautifully! Thanks! But I want to ask, how do I do the same thing, but for recording devices? What part of the script would I have to replace? Thanks again!

    • http://theitbros.com/ Brian Jackson

      Good question. This is worth a blog post.

  • Yakko

    For the Finnish Windows 8.1 users:

    *F6::
    Run, mmsys.cpl
    WinWait,Ääni
    ControlSend,SysListView321,{Down 3}
    ControlClick,&Aseta oletus
    ControlSend,SysListView321,{Down 1}
    ControlClick,OK
    return

    *F7::
    Run, mmsys.cpl
    WinWait,Ääni
    ControlSend,SysListView321,{Down 2}
    ControlClick,&Aseta oletus
    ControlSend,SysListView321,{Down 1}
    ControlClick,OK
    return

  • InsanePorcupine

    How do you change the order in which devices are listed? Everytime I plug in a headset the order changes and everything goes to hell.

  • Adam

    Great script – thanks for sharing!