Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Changing default audio device


  • Please log in to reply
104 replies to this topic
engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
Checnge the tab first

send different keys

...
Run, mmsys.cpl
WinWait,Sound
ControlSend,[color=#FF0000]SysTabControl321[/color],{Right}
...



ddlordy
  • Members
  • 12 posts
  • Last active: Jun 13 2012 05:56 AM
  • Joined: 13 Jun 2012
Thanks for your help engunner. I implemented your suggest. The toggling between playback has always work but the recording on the other hand changes once but doesn't toggle. Here's the code that I'm using.
*F12::
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
if(!isEnabled)
{
  ControlSend,SysListView321,{Down 2}
}
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1

Run, mmsys.cpl
WinWait,Sound
ControlSend,SysTabControl321,{Right}
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
if(!isEnabled)
{
  ControlSend,SysListView321,{Down 2}
}
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return

Checnge the tab first

send different keys

...
Run, mmsys.cpl
WinWait,Sound
ControlSend,[color=#FF0000]SysTabControl321[/color],{Right}
...



ddlordy
  • Members
  • 12 posts
  • Last active: Jun 13 2012 05:56 AM
  • Joined: 13 Jun 2012
In reference to above, any suggestion why recording default device changes once but doesn't toggle back?

jmeyer1980
  • Members
  • 2 posts
  • Last active: Aug 15 2012 04:35 PM
  • Joined: 15 Aug 2012
I run win7 x64... so, of course, the registry editing script doesn't work for me. I am currently using a long and clunky script to do this and, since it does work, didnt want to fool with it anymore... lol.

But I tried really hard to locate the registry key that holds our answer... to no avail.

I downloaded and used a registry snapshot program to take a shot of the registry before changing to my alternate audio device... changing.. and snapping again...

Guess what? No Changes.

Unless I am doing something wrong... there were NO changes to the registry within win7 x64.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
was the registry snapshot program 64 bit or 32 bit? if it wasn't the right flavor (and especially if it was 32 bit) then it might not see the change in the other half of the registry.

There is a new command in ahk to switch whether AHK sees the 32bit registry or the 64 bit registry. Have you looked at that at all?

jmeyer1980
  • Members
  • 2 posts
  • Last active: Aug 15 2012 04:35 PM
  • Joined: 15 Aug 2012
Good point. The snapshot program may have been 32 bit. And the program is not related to AHK in any way.

I will try to find a x64 registry snapshot program. Thanks. Found Regshot x64. It looks like it hangs for a moment, but eventually finishes the job. I had to do one comparison when I switched from realtek to soundblaster... and another comparison when i switched back.

On MY system the following keys were changed... the problem is... the binary values never change in the exact same way. I have ran over 10 comparisons and not one of them ended up with the same hex binary code.

Switching from realtek to soundblaster usb:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{fbf9909c-e8d9-45a5-8a98-130177c4c1e6}\Role:0:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{fbf9909c-e8d9-45a5-8a98-130177c4c1e6}\Role:1:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{fbf9909c-e8d9-45a5-8a98-130177c4c1e6}\Role:2:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{71ff9d9b-8490-466b-ae58-bb73636a8394}\Role:0: 
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{71ff9d9b-8490-466b-ae58-bb73636a8394}\Role:1: 
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{71ff9d9b-8490-466b-ae58-bb73636a8394}\Role:2: 

Switching to from Soundblaster usb to realtek:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{3492148a-7e5f-4fd0-b33b-e9e82a257084}\Role:0:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{3492148a-7e5f-4fd0-b33b-e9e82a257084}\Role:1:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{3492148a-7e5f-4fd0-b33b-e9e82a257084}\Role:2:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{f3e5a4c3-c45c-43be-a446-23bd2bd43b52}\Role:0:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{f3e5a4c3-c45c-43be-a446-23bd2bd43b52}\Role:1:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{f3e5a4c3-c45c-43be-a446-23bd2bd43b52}\Role:2:

I was hoping that this would work with xaviers code below...

The most easy and non-obstructing way to do this is via RegRead and ReadWrite.

Windows stores the default playback device under the "HKEY_CURRENT_USER\ Software\Microsoft\Multimedia\Sound Mapper\Playback" key.

Doing something like this will switch between my onboard realtek and creative audigy se sounds cards that I have on my rig:

; Toggle Sound Devices
!+s::
    RegRead, Device, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback
    if(Device = "Realtek HD Audio output")
    {
        RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, Sound Blaster Audigy
        Device := "Audigy"
    }
    else
    {
        RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, Realtek HD Audio output
        Device := "Realtek"
    }
    
    ToolTip, % "Sound Device: " Device
    SetTimer, ResetToolTip, 1000
return


; Clear the ToolTip
ReSetToolTip:
    ToolTip
    SetTimer, ReSetToolTip, Off
return


Change the "if(Device = ...)" line with your sound card names.

Unfortunately I haven't found a way to make windows update all the programs running with the new default sound card device. That way even if I change the default by hand I have to restart my processes to update them with the new sound device.


And using that code above, I would assume that it would end up looking like this... but once again... the binaries do not change in exactly the same way every time.

; Toggle Sound Devices
^#s::
    RegRead, Device, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{3492148a-7e5f-4fd0-b33b-e9e82a257084}\Role:0:
    if(Device = "DC 07 08 00 06 00 12 00 01 00 09 00 05 00 A6 03") ;If we are currently using Realtek - switch to Wireless
    {
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{fbf9909c-e8d9-45a5-8a98-130177c4c1e6}\Role:0:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{fbf9909c-e8d9-45a5-8a98-130177c4c1e6}\Role:1:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{fbf9909c-e8d9-45a5-8a98-130177c4c1e6}\Role:2:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{71ff9d9b-8490-466b-ae58-bb73636a8394}\Role:0:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{71ff9d9b-8490-466b-ae58-bb73636a8394}\Role:1:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{71ff9d9b-8490-466b-ae58-bb73636a8394}\Role:2:

        Device := "Wireless"
    }
    else ;if we were already on the wireless device... then we will swap over to the Realtek
    {
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{3492148a-7e5f-4fd0-b33b-e9e82a257084}\Role:0:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{3492148a-7e5f-4fd0-b33b-e9e82a257084}\Role:1:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{3492148a-7e5f-4fd0-b33b-e9e82a257084}\Role:2:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{f3e5a4c3-c45c-43be-a446-23bd2bd43b52}\Role:0:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{f3e5a4c3-c45c-43be-a446-23bd2bd43b52}\Role:1:
		RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{f3e5a4c3-c45c-43be-a446-23bd2bd43b52}\Role:2:
        Device := "Realtek"
    }
    
    ToolTip, % "Sound Device: " Device
    SetTimer, ResetToolTip, 1000
return


; Clear the ToolTip
ReSetToolTip:
    ToolTip
    SetTimer, ReSetToolTip, Off
return

I think this one goes out to greater minds than mine. If anyone can use this information to update XavierGr's code, I would greatly appreciate it.

wynwar
  • Guests
  • Last active:
  • Joined: --
for all those who don't want to code :
http://www.quicksoundswitch.toflo.de/

kkonstantinidis
  • Guests
  • Last active:
  • Joined: --
This may be an old thread but I would like to post the script that solved my problem and helped me switch both playback and recording audio devices. In my case, the 1st device is the headset and the 3rd on the list are the speakers and the in-built microphone:

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

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

Goni
  • Guests
  • Last active:
  • Joined: --
Thanks all for thiese great tips. I had some problems due to my windows being in french, i solved those using AHK spy. Here's what i had to change if any other french try using the scripts from this topic.

&Set Default --> Par &défaut
WinWait Sound --> WinWait Son

Diamond
  • Members
  • 198 posts
  • Last active: Dec 02 2015 11:18 AM
  • Joined: 31 Mar 2006

Ok, so here's my attempt at this type of script.  I've been using it for a while now and it seems to work pretty well.  This is specifically for Vista/7.


 

Function SelectDevice()


 

Accepts two parameters.  The name of the device as listed in the "Sound" dialog and the mode.  I.E. whether to search in the "Playback" or "Recording" tab.  "P" or leave blank for playback and "R" for recording.


 

^+F9::SelectDevice("Speakers Creative SB Audigy 4 (WDM)")
^+F10::SelectDevice("Speakers Plantronics Wireless Audio")
^+F11::SelectDevice("Microphone Creative SB Audigy 4 (WDM)", "R")
^+F12::SelectDevice("""What U Hear"" Creative SB Audigy 4 (WDM)", "R")


 

SelectDevice(Device,Mode = "P") {
    SetBatchLines -1
    DetectHiddenWindows On
    If Mode = P
        Run rundll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,0
    Else If Mode = R
        Run rundll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,1
    Else
      {
        TrayTip,, Invalid parameter.`nValid options are "P" for playback or "R" for recording., 10, 17
        Return
      }
    WinWait Sound ahk_class #32770
    WinHide
    ControlGet List, List,, SysListView321
    StringReplace List, List, `t, %A_Space%, A
    IfNotInString List, %Device%
      {
        TrayTip,, %Device% not found., 10, 17
        ControlSend Cancel, {Enter}
        Return
      }
    Loop Parse, List, `n
        IfInString A_LoopField, %Device%
          {
            If RegExMatch(A_LoopField, "Default Device$")
              {
                TrayTip,, %Device% is already set as default., 10, 17
                ControlSend Cancel, {Enter}
                Return
              }
            If RegExMatch(A_LoopField, "(Disabled$|Disconnected$|Not plugged in$)")
              {
                TrayTip,, %Device% not available., 10, 17
                ControlSend Cancel, {Enter}
                Return
              }
            DeviceNumber := A_Index
            Break
          }
    If DeviceNumber = 1
        ControlSend SysListView321, {Home}
    Else
      {
        DeviceNumber -= 1
        ControlSend SysListView321, {Home}{Down %DeviceNumber%}
      }
    ControlSend &Set Default, {Space}
    ControlSend OK, {Enter}
    Return
}


phreichmuth
  • Members
  • 1 posts
  • Last active: Jun 11 2013 11:52 AM
  • Joined: 11 Jun 2013

I have written a script that allows to set audio device 1 (default windows audio device) by Win+1 and a second audio device by Win+2 in Windows XP itself and in Cisco IP Communicator as well. I am sure, it can be modified to set other devices or to chose between more than two.

To check what audio device is set in Windows or the Cisco IP Communicator it read regestry keys. This is to avoid changing correct settings to wrong ones because Autohotkey does not allow to read selected entries from dropdown menues (or I at least do not know how to do this):

; Set Sounddevice 1 (Conexant HD Audio output / Default Windows Audio Device)
#1::

; Read audio Device in from Cisco IP Communicator
RegRead, CiscoDevice, HKEY_CURRENT_USER, Software\Cisco Systems`, Inc.\Communicator, AudioHandsetDevice
Device := "Conexant HD Audio"

; Change it to audio device 1 (Conexant HD Audio output) or Default Windows Audio Device respectivelly if it is not already set.
if(CiscoDevice = "Plantronics .Audio 400 DSP")
{
    Run %A_ProgramFiles%\Cisco Systems\Cisco IP Communicator\communicatork9.exe
    WinWait, Cisco
    IfWinNotActive, Cisco WinActivate, Cisco
    WinWaitActive, Cisco
    Send, !{s}
    Sleep, 25
    Send, {right 2}
    Sleep, 25
    Send, {Tab 3}
    Sleep, 25
    Send, {down}
    Sleep, 25
    Send, {Tab}
    Sleep, 25
    Send, {down}
    Sleep, 25
    Send, {Tab}
    Sleep, 25
    Send, {down}
    Sleep, 25
    Send, {Tab}
    Sleep, 25
    Send, {down 2}
    Sleep, 25
    Send, {Enter}	
    WinWait, Cisco
    IfWinNotActive, Cisco WinActivate, Cisco
    WinWaitActive, Cisco
    Send, !{F4}
}

; Read Windows audio device
RegRead, WindowsDevice, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback

; Change it to audio device 1 (Conexant HD Audio output) if it is not already set.
if (WindowsDevice = "Plantronics .Audio 400 DSP")
{
    Run, mmsys.cpl
    WinWait, Eigenschaften von Sounds und Audiogeräte
    IfWinNotActive, Eigenschaften von Sounds und Audiogeräte WinActivate, Eigenschaften von Sounds und Audiogeräte
    WinWaitActive, Eigenschaften von Sounds und Audiogeräte
    Send, ^{Tab 2}
    Sleep, 25
    Send, {Down}
    Sleep, 25
    Send, {Tab 3}
    Sleep, 25
    Send, {Down}
    Sleep, 25
    Send, !b
    Sleep, 25
    Send, ^{Tab}
    Sleep, 25
    Send, {Up}
    Sleep, 25
    Send, {Tab 3}
    Sleep, 25
    Send, {Up}
    Sleep, 25
    Send, {Enter}
}

; Show tool tip with now active audio device
ToolTip, % "Sound Device: " Device
    SetTimer, ResetToolTip, 2000
return

; Set Sounddevcie 2 (Plantronics .Audio 400 DSP)
#2::

; Read audio Device in from Cisco IP Communicator
RegRead, CiscoDevice, HKEY_CURRENT_USER, Software\Cisco Systems`, Inc.\Communicator, AudioHandsetDevice
Device := "Plantronics .Audio 400 DSP"

; Change it to audio device 2 (Plantronics .Audio 400 DSP) or Default Windows Audio Device respectivelly if it is not already set.
if(CiscoDevice = "Default Windows Audio Device")
{
    Run %A_ProgramFiles%\Cisco Systems\Cisco IP Communicator\communicatork9.exe
    WinWait, Cisco
    IfWinNotActive, Cisco WinActivate, Cisco
    WinWaitActive, Cisco
    Send, !{s}
    Sleep, 25
    Send, {right 2}
    Sleep, 25
    Send, {Tab 3}
    Sleep, 25
    Send, {up}
    Sleep, 25
    Send, {Tab}
    Sleep, 25
    Send, {up}
    Sleep, 25
    Send, {Tab}
    Sleep, 25
    Send, {up}
    Sleep, 25
    Send, {Tab}
    Sleep, 25
    Send, {up}
    Sleep, 25
    Send, {Enter}		
    WinWait, Cisco
    IfWinNotActive, Cisco WinActivate, Cisco
    WinWaitActive, Cisco
    Send, !{F4}
}

; Read Windows audio device
RegRead, WindowsDevice, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback

; Change it to audio device 2 (Plantronics .Audio 400 DSP) if it is not already set.
if (WindowsDevice = "Conexant HD Audio output")
{
    Run, mmsys.cpl
    WinWait, Eigenschaften von Sounds und Audiogeräte
    IfWinNotActive, Eigenschaften von Sounds und Audiogeräte WinActivate, Eigenschaften von Sounds und Audiogeräte
    WinWaitActive, Eigenschaften von Sounds und Audiogeräte
    Send, ^{Tab 2}
    Sleep, 25
    Send, {Down}
    Sleep, 25
    Send, {Tab 3}
    Sleep, 25
    Send, {Down}
    Sleep, 25
    Send, !b
    Sleep, 25
    Send, ^{Tab}
    Sleep, 25
    Send, {Up}
    Sleep, 25
    Send, {Tab 3}
    Sleep, 25
    Send, {Up}
    Sleep, 25
    Send, {Enter}
}

; Show tool tip with now active audio device
ToolTip, % "Sound Device: " Device
    SetTimer, ResetToolTip, 2000
return


; Clear the ToolTip
ReSetToolTip:
    ToolTip
    SetTimer, ReSetToolTip, Off
return

Have fun with it!

Regards

Philipp



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

VA.ahk has been updated with a function for changing the default audio device.  Here's an example for swapping between two playback devices:

SwapAudioDevice("Speakers", "Digital Output")

SwapAudioDevice(device_A, device_B)
{
    ; Get device IDs.
    A := VA_GetDevice(device_A), VA_IMMDevice_GetId(A, A_id)
    B := VA_GetDevice(device_B), VA_IMMDevice_GetId(B, B_id)
    if A && B
    {
        ; Get ID of default playback device.
        default := VA_GetDevice("playback")
        VA_IMMDevice_GetId(default, default_id)
        ObjRelease(default)
        
        ; If device A is default, set device B; otherwise set device A.
        VA_SetDefaultEndpoint(default_id == A_id ? B : A, 0)
    }
    ObjRelease(B)
    ObjRelease(A)
    if !(A && B)
        throw Exception("Unknown audio device", -1, A ? device_B : device_A)
}


D3vys
  • Members
  • 1 posts
  • Last active: Aug 21 2013 07:16 PM
  • Joined: 21 Aug 2013

code win xp registry?sound playback audio device only not change with Bluetooth Advanced Audio(IVT).., Connected only e2Esoft VAudio software Audio Repeater(dsp_stacker)->Joesoft Hear And SRS Audio Sandbox connected for Radio Smartphone RDS



Aaron832
  • Members
  • 1 posts
  • Last active: Sep 06 2013 07:59 PM
  • Joined: 06 Sep 2013

 

Ok, so here's my attempt at this type of script.  I've been using it for a while now and it seems to work pretty well.  This is specifically for Vista/7.

 

Function SelectDevice()

 

Accepts two parameters.  The name of the device as listed in the "Sound" dialog and the mode.  I.E. whether to search in the "Playback" or "Recording" tab.  "P" or leave blank for playback and "R" for recording.

 

^+F9::SelectDevice("Speakers Creative SB Audigy 4 (WDM)")
^+F10::SelectDevice("Speakers Plantronics Wireless Audio")
^+F11::SelectDevice("Microphone Creative SB Audigy 4 (WDM)", "R")
^+F12::SelectDevice("""What U Hear"" Creative SB Audigy 4 (WDM)", "R")

 

SelectDevice(Device,Mode = "P") {
    SetBatchLines -1
    DetectHiddenWindows On
    If Mode = P
        Run rundll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,0
    Else If Mode = R
        Run rundll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,1
    Else
      {
        TrayTip,, Invalid parameter.`nValid options are "P" for playback or "R" for recording., 10, 17
        Return
      }
    WinWait Sound ahk_class #32770
    WinHide
    ControlGet List, List,, SysListView321
    StringReplace List, List, `t, %A_Space%, A
    IfNotInString List, %Device%
      {
        TrayTip,, %Device% not found., 10, 17
        ControlSend Cancel, {Enter}
        Return
      }
    Loop Parse, List, `n
        IfInString A_LoopField, %Device%
          {
            If RegExMatch(A_LoopField, "Default Device$")
              {
                TrayTip,, %Device% is already set as default., 10, 17
                ControlSend Cancel, {Enter}
                Return
              }
            If RegExMatch(A_LoopField, "(Disabled$|Disconnected$|Not plugged in$)")
              {
                TrayTip,, %Device% not available., 10, 17
                ControlSend Cancel, {Enter}
                Return
              }
            DeviceNumber := A_Index
            Break
          }
    If DeviceNumber = 1
        ControlSend SysListView321, {Home}
    Else
      {
        DeviceNumber -= 1
        ControlSend SysListView321, {Home}{Down %DeviceNumber%}
      }
    ControlSend &Set Default, {Space}
    ControlSend OK, {Enter}
    Return
}

 

Thanks a bunch for this!  For me, this method works the best for Windows 7!



neilputt
  • Members
  • 1 posts
  • Last active: Dec 08 2013 01:09 AM
  • Joined: 08 Dec 2013

I took a different route for a few reasons. First, mmsys.cpl sometimes takes a minute or two to open for me. I think it's a driver issue. Second, it seems kinda ghetto to open the window and manipulate the GUI. Finally, if I had to change my audio device while I'm gaming, I'm worried it would steal the focus.
 
Instead, I used NirCmd, which expands on AHK's Send command a bit. NirCmd seems legit but YMMV. It's relatively straightforward:

;#NotrayIcon
#SingleInstance force

#F9::
 setDevice("USBDAC")
return

#F10::
 setDevice("G930")
return

#F11::
 setDevice("Speakers")
return

#F12::
 setDevice("FrontHeadphones")
return

setDevice(device){
 run nircmd.exe setdefaultsounddevice %device% ;default audio device
 run nircmd.exe setdefaultsounddevice %device% 2 ;default communication device
 TrayTip Audio Device Selected, %device%, , 1
}

Keep in mind you can rename your audio devices by right clicking on each and going to Properties.