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
  • Guests
  • Last active:
  • Joined: --

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.


Thank you so much for your indication of the registry value!!!

I don't run external .exe files, for security reasons, so I've created a vbs file with a few .bat files to switch between my 3 output profiles (default sound card, usb card and bluetooth). I posted all the code at <!-- m -->http://www.4shared.c...nd_scripts.html<!-- m -->

The most important thing I think of doing that is that everybody can look and understand the code before to run, instead of running executables files that can contain viruses, spyware, adware...

Gilberto MSN
  • Guests
  • Last active:
  • Joined: --

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.


Thank you so much for your indication of the registry value!!!

I don't run external .exe files, for security reasons, so I've created a vbs file with a few .bat files to switch between my 3 output profiles (default sound card, usb card and bluetooth). I posted all the code at http://www.4shared.c...nd_scripts.html

The most important thing I think of doing that is that everybody can look and understand the code before to run, instead of running executables files that can contain viruses, spyware, adware...

tatoosh
  • Members
  • 4 posts
  • Last active: Mar 12 2012 10:12 AM
  • Joined: 22 Jun 2009
i don't have the soundmapper in the registry.
what to to now?

i use Win7 Prof. x64
Posted Image

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009

i don't have the soundmapper in the registry.
what to to now?

i use Win7 Prof. x64
Posted Image


Me neither .

angela griffie
  • Guests
  • Last active:
  • Joined: --

I actually use AHK for switching between my two soundcards.
My script is for WinXP, so if you have another OS, you may need to change window titles etc.

Run, mmsys.cpl
Sleep, 100
WinWait, Sounds and Audio Devices Properties
IfWinNotActive, Sounds and Audio Devices Properties WinActivate, Sounds and Audio Devices Properties
WinWaitActive, Sounds and Audio Devices Properties
Send, ^{Tab}
Sleep, 100
Send, ^{Tab}
Sleep, 100
WinWait, Sounds and Audio Devices Properties
IfWinNotActive, Sounds and Audio Devices Properties WinActivate, [list=]Sounds and Audio Devices Properties[/list]WinWaitActive, Sounds and Audio Devices Properties
Send, {Down}
Sleep, 50
Send, !A
Sleep, 100
Send, {Enter}

As a sidenote - this script switches between two audio devices and I don't have a clue which device it would select if you have more.

[list][/list]

Happy Boy
  • Members
  • 1 posts
  • Last active: Aug 13 2010 10:55 AM
  • Joined: 13 Aug 2010

^+`::
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
return


This works great for the most part. There is some room for improvement though.

When you run the script and the mouse cursor happens to locate in the same area as the mmsys.cpl window, the script stops and only shows the mmsys.cpl window.

How do you avoid is? I suppose one solution would be to position the mouse cursor to a "distant" location prior to running mmsys.cpl but this solution would not be 100% proof since the window itself could open up at that distant location on the screen.

Can you guys think of other solutions?

LorenAmelang
  • Members
  • 4 posts
  • Last active: May 25 2011 11:07 PM
  • Joined: 20 Sep 2010
Somehow my Win7 insists on defaulting the S/PDIF output to 24-bit mode, and not switching back to 16-bit mode when I open a browser window. I've made a hotkey that fixes this, except for one thing. Windows randomly re-arranges the positions of the Playback Devices in the SysListView321 control, breaking any code that relies on cursor positions or up/down commands.

As you can see in the commented-out code below, I've tried to get the actual item names instead of using positions, but nothing has worked in this particular control. I guess a "SysListView" is a different animal that LV_GetText() can't work with? Or have I just missed some detail? The loop loops, but it never reads any text.

Is there some other way to avoid using up/down position commands? The "toggle between two items" example won't work, because there are several Bluetooth audio entries in the list, and they aren't always available, so Speakers is the only usable alternative to S/PDIF.


#+A::
Run,mmsys.cpl
WinWait,Sound
IfWinNotActive,Sound WinActivate,Sound
WinWaitActive,Sound
ControlSend,SysListView321,{PgUp}  ; Click the first item  ; doesn't help count problem

;Gui,ListView,SysListView321  ; Make ListView active  ; doesn't help...
;MsgBox,0,Count,% LV_GetCount()  ; Show count for loop iteration
;RowNumber = 0  ; This causes the first loop iteration to start the search at the top of the list.
;Loop,4  ; causes four iterations, but all blank text
;Loop % LV_GetCount()  ; as above, count is zero
;{
;    MsgBox,0,Iter,%A_Index%  ; Show loop iteration
;    LV_GetText(RetrievedText, A_Index)
;    MsgBox,0,Text,%RetrievedText%  ; Show item text
;    if InStr(RetrievedText, "S/PDIF")
;        {
;        MsgBox,0,Select,%A_Index%  ; Show selection
;        LV_Modify(A_Index, "Select")  ; Select each row whose first field contains the filter-text.
;        }
;}

; 100905 - S/PDIF moved to top position, don't step down:
; 100919 - back to second place, step down:
ControlSend,SysListView321,{Down}  ; click SPDIF0
Sleep, 500
ControlClick,&Properties
;Pause
;Send, ^{Tab}  ; S/PDIF only has four tabs, but test with speakers has five
;Sleep, 50
Send, ^{Tab}
Sleep, 50
Send, ^{Tab}
Sleep, 50
Send, ^{Tab}
Sleep, 500  ; now on Advanced tab
ControlClick,&Default Format
Send, {PgUp}  ; choose first item in list, 16,44
Sleep, 500
Send, {Enter}
Sleep, 500
ControlClick,&OK
WinWaitActive,Sound  ; back on Playback tab
; S/PDIF shows as active but isn't - must re-select it
Sleep, 500
; 100905 - S/PDIF moved to top position, don't step up:
; 100919 - back to second place, step up:
ControlSend,SysListView321,{Up}  ; click Speakers
; step down instead:
;ControlSend,SysListView321,{Down}  ; click G1200
; setting an unavailable Bluetooth device doesn't work; move to speakers:
;ControlSend,SysListView321,{Down}  ; click Speakers
ControlClick,&Set Default
Sleep, 500
ControlSend,SysListView321,{Down}  ; click SPDIF0
;ControlSend,SysListView321,{PgUp}  ; click SPDIF0
ControlClick,&Set Default
Sleep, 500
Send, {Tab}  ; make Playback tab active
Send, {Tab}  ; make Sound panel active
;ControlClick,&OK  ; doesn't work...
Send {Enter}
return

Any clues appreciated!

harrison3001
  • Members
  • 1 posts
  • Last active: Jan 02 2017 10:53 PM
  • Joined: 23 Sep 2010
Based on the XP script by procyon i wrote a script for Windows 7 that works flawlessly. Cause I'm a newbie about AutoHotkey i use only keystrokes, to go to the second device we need two down arrow keystrokes, to go to the first we need only one. You can find the script at <!-- m -->http://snipplr.com/v... ... nd-device/<!-- m -->. Hope this help.

----------------
Now playing: MoShang - Comfort Zone
via FoxyTunes

LorenAmelang
  • Members
  • 4 posts
  • Last active: May 25 2011 11:07 PM
  • Joined: 20 Sep 2010
I believe I've solved this (Windows hasn't shuffled the positions of the list entries yet, but I can see the mechanism working).

The key was finding
ControlGet, OutputVar, List, Col1, SysListView321, A  ; get column 1, all rows
Which actually does retrieve a list of all the playback devices. I had tried to use
ControlGet, OutputVar, FindString, "Speakers / HP", SysListView321, A
but it returns position 1 and no error no matter what I search for. I didn't manage to figure out what it really does, so I tried alternatives. This steps through all of the "List" items found by ControlGet, and lets me react to each one if appropriate:
Loop, Parse, OutputVar, `n  ; Rows are delimited by linefeeds (`n)

There are lots of msgbox debugging steps commented out of this code. If you want to see the mechanism work you can restore some of them. The "sleep, 500" delays are so I can watch the action graphically while the code runs.

#+A::
Run,mmsys.cpl
WinWait,Sound
IfWinNotActive,Sound WinActivate,Sound
WinWaitActive,Sound
ControlSend,SysListView321,{PgUp}  ; Click the first item so we know where we are
Sleep, 500

SpdifAvail := 0
SpdifSteps := 0
SpeakerAvail := 0
SpeakerSteps := 0

; Following works for testing, commented out for normal use
;ControlGet, count, List, count, SysListView321, A
;msgbox lines = %count%

; Following returns position 1, error 0, regardless of string searched:
; ControlGet, OutputVar, FindString, "Speakers / HP", SysListView321, A
; msgbox "Speakers / HP" position is %outputvar%
; msgbox "Speakers / HP" error is %ErrorLevel%

ControlGet, OutputVar, List, Col1, SysListView321, A  ; get column 1, all rows
; Following several msgboxes for testing, commented out for normal use
;msgbox %outputvar%

Loop, Parse, OutputVar, `n  ; Rows are delimited by linefeeds (`n)
	{
	RowNumber := A_Index
	Loop, Parse, A_LoopField, %A_Tab%  ; Fields (columns) in each row are delimited by tabs (A_Tab)
		{
;		MsgBox Row #%RowNumber% Col #%A_Index% is %A_LoopField%.
		if InStr(A_LoopField, "Speakers")  ; save Speakers position
			{
;			MsgBox, found: Speakers(Steps)  row: %RowNumber%  ; Show selection
			SpeakerAvail := 1
			SpeakerSteps := RowNumber -1
;			MsgBox, "SpeakerSteps" = %SpeakerSteps%
			}
		if InStr(A_LoopField, "S/PDIF")  ; use S/PDIF if available
			{
;			MsgBox, found: S/PDIF(Steps)  row: %RowNumber%  ; Show selection
			SpdifAvail := 1
			SpdifSteps := RowNumber -1
;			MsgBox, "SpdifSteps" = %SpdifSteps%
			}
		}
	Sleep, 50
	}

if SpdifAvail
	{
	Loop, %SpdifSteps%
		{
;		MsgBox, SpdifStep %A_Index%
		ControlSend,SysListView321,{Down}  ; click down to SPDIF0
		Sleep, 50
		}
	Sleep, 500
	ControlClick,&Properties
	Send, ^{Tab}  ; S/PDIF has four tabs, we want the last one
	Sleep, 50
	Send, ^{Tab}
	Sleep, 50
	Send, ^{Tab}
	Sleep, 500  ; now on Advanced tab
	ControlClick,&Default Format
	Send, {PgUp}  ; choose first item in list, 16,44
	Sleep, 500
	Send, {Enter}
	Sleep, 500
	ControlClick,&OK
	WinWaitActive,Sound  ; back on Playback tab
	; S/PDIF shows as active but isn't - must re-select it
	; setting an unavailable Bluetooth device doesn't work; move to speakers:
	Sleep, 500
	ControlSend,SysListView321,{PgUp}  ; Click the first item so we know where we are
	Loop, %SpeakerSteps%
		{
		ControlSend,SysListView321,{Down}  ; click down to Speakers
		Sleep, 50
		}
	Sleep, 500
	ControlSend,SysListView321,{PgUp}  ; Click the first item so we know where we are
	Loop, %SpdifSteps%
		{
		ControlSend,SysListView321,{Down}  ; click down to SPDIF0
		Sleep, 50
		}
	ControlClick,&Set Default
	Sleep, 500
	}
else if SpeakerAvail  ; use Speakers if available and S/PDIF is not available
	{
	MsgBox, found: Speakers(NoSpdif)  row: %RowNumber% ; Show selection
	Loop, %SpeakerSteps%
		{
		ControlSend,SysListView321,{Down}  ; click down to Speakers
		Sleep, 50
		}
	ControlClick,&Set Default
	Sleep, 500
	}

; ControlClick,&OK  ; doesn't work...
Send, {Tab}  ; make Configure active
Send, {Tab}  ; make Properties active
Send, {Tab}  ; make OK active
Send {Enter}
return

Hopefully this will work no matter how Windows re-arranges the list items.

XPdrivers
  • Guests
  • Last active:
  • Joined: --
Guys, seriously, that script for Win7 sucks.
You better roll back to win XP and get Xavier's registry based script working.
Sue your computer manufacturer if they dont provide XP drivers for all the stuff that you paid for. There must be freedom of choice for OS.

Many here might think that someone will come to fix that for Win7, but maybe that wont happen, as it is the case for a bunch of great code on AHK forum that wont work on newer Win OS because MS has to keep on changing the look of the same product so as to make money.

ajkessel
  • Guests
  • Last active:
  • Joined: --
Here's another approach. Still a little clunky, but this will scroll to the next sound card in Windows 7 and loop back to the top from the bottom. You can uncomment the msgbox toward the end if you want the selected card to be displayed; and/or comment out the SoundPlay line if you don't want an audio alert on the new card.

There is probably a way to make this a little more efficient; ideas welcome.
^+`::
Run,mmsys.cpl
WinWait,Sound
IfWinNotActive,Sound WinActivate,Sound
WinWaitActive,Sound
ControlSend,SysListView321,{PgUp}  
x := 1
ControlGet, isEnabled, Enabled,,&Set Default
ControlGet, max, List, Count, SysListView321
while (isEnabled AND x <= max) {
   ControlSend,SysListView321,{Down}  
   ControlGet, isEnabled, Enabled,,&Set Default
   x := x+1
}
if (x >= max) {
   x := 1
} else {
   x := x+1
}
sleep 50
ControlSend,SysListView321,{PgUp}  
while (x > 1) {
  sleep 50
  ControlSend,SysListView321,{Down}  
  x := x-1
}
ControlGet, Current, List, Selected, SysListView321
; msgbox %Current%
ControlClick,&Set Default
ControlClick,OK
SoundPlay *48

return
[/code]

  • Guests
  • Last active:
  • Joined: --

Guys, seriously, that script for Win7 sucks.
You better roll back to win XP and get Xavier's registry based script working.
Sue your computer manufacturer if they dont provide XP drivers for all the stuff that you paid for. There must be freedom of choice for OS.

Many here might think that someone will come to fix that for Win7, but maybe that wont happen, as it is the case for a bunch of great code on AHK forum that wont work on newer Win OS because MS has to keep on changing the look of the same product so as to make money.


Uh, what's wrong with it? Works perfectly for me, albeit clunky. For my purposes, it's A OK.

  • Guests
  • Last active:
  • Joined: --
I had some issues with the simple Win7 scripts. Simply adding KeyWait Control and KeyWait Shift worked wonders.
Too bad there isn't an apparent simple way to do all this in the background.

NEW
  • Guests
  • Last active:
  • Joined: --
I've tried all your scripts, but they all stop on WinWait,Sound. Do you have any ideas?

NEW
  • Guests
  • Last active:
  • Joined: --

I've tried all your scripts, but they all stop on WinWait,Sound. Do you have any ideas?


:) Found the problem, I have a different name for the window