Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: How to toggle between default sound device using hotkey

31 Aug 2014   #11
AphoticBass

Windows 7 Ultimate 32 bit
 
 

would you guys be able to write a script to toggle between these 3 sound devices?


How to toggle between default sound device using hotkey-soudn-devices.jpg




My System SpecsSystem Spec
.
18 Sep 2014   #12
timmybones

Windows 7 Home Premium 64bit
 
 

*Edit: I realized after posting the tabbing is lost, which makes the scripts a bit more difficult to read. Here is a link to a text file with the spacing preserved

https://drive.google.com/file/d/0Bwm...it?usp=sharing

The reason the scripts posted so far don't work for everyone is that they are hard-coded to work in a specific scenario for device installation. All the scripts do is try to enable either the first device in the list or the third, whichever it's able to.

This doesn't work for me because my device list isn't arranged that way, and apparently the same is true for others, so I wrote the script below instead to find specific devices (the script is based on the ones posted here but modified, primarily just the loop) (shortcut is windows key + ctrl + s)

#+s::
Run, mmsys.cpl
WinWait,Sound
Loop{
ControlSend,SysListView321,{Down}
ControlGet, device, List,Selected,SysListView321
if InStr(device, "Speakers")=1 {
ControlGet, isEnabled, Enabled,,&Set Default
if isEnabled {
found:=1
break
}
}
if InStr(device, "m/m")=1 {
ControlGet, isEnabled, Enabled,,&Set Default
if isEnabled {
found:=1
break
}
}
}
if (found)
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return

That looks for devices called "Speakers" or "m/m" that are not currently the default and sets the default to the first of those two it finds. You can modify this to work for different device names, just edit the "Speakers" and "m/m" strings in that script as needed.

In cases like AphoticBass' where multiple devices have the same primary name, you will need to add a tab after the primary name in the string and then include text from the next line as well to get a unique name to look for, e.g. "Speakers<tab>SkullCandy" for the screenshot above (I can't actually insert a tab in this post, so <tab> should be the actual tab character).

AphoticBass - to do what I believe you really want, the script below will just cycle through all eligible devices, so you can use it to go through your three as needed (this will work for anyone else with any number of eligible devices in the list, though). (shortcut is windows key + ctrl + d)

#+d::
lineCount:=""
defaultLine:=""
found:=""
isEnabled:=""
line:=""
Run, mmsys.cpl
WinWait,Sound
;we'll need the total line count later
ControlGet, lineCount, List,Count,SysListView321
;find which device is the current default
Loop {
ControlSend,SysListView321,{Down}
ControlGet, line, List,Selected,SysListView321
if InStr(line,"Default Device")>0 {
ControlGet, defaultLine, List,Count Focused,SysListView321
break
}
;need to stop if we get to the bottom
ControlGet, line, List,Count Focused,SysListView321
if (line=lineCount) {
break
}
}
if (!defaultLine) {
MsgBox Error: couldn't find a default device currently in use.
return
}
;find the next eligible device in the list after the default
Loop {
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
if (isEnabled) {
found:=1
break
}
;need to stop if we get to the bottom
ControlGet, line, List,Count Focused,SysListView321
if (line=lineCount) {
break
}
}
if (!found) {
;if we are here we didn't find another eligible device later in the list,
;so need to start at the top again
Loop, % lineCount-1 {
ControlSend,SysListView321,{Up}
}
;start back down the list
Loop {
ControlGet, isEnabled, Enabled,,&Set Default
if (isEnabled) {
found:=1
break
}
;need to stop if we get to the bottom (this would mean something is wrong, though)
ControlGet, line, List,Count Focused,SysListView321
if (line=lineCount) {
break
}
ControlSend,SysListView321,{Down}
}
}
if (found)
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return

I just learned AutoHotKey tonight and handling cycling back to the top of the list is not really trivial based on how this language works, so let me know if you run into any issues with the script. It worked for me, but I didn't do very extensive testing, and only tested on one machine.
My System SpecsSystem Spec
23 Nov 2015   #13
BurnOmatic

Windows 7 Pro
 
 

this right here works beautifully https://code.google.com/p/audioswitch/
My System SpecsSystem Spec
.

Reply

 How to toggle between default sound device using hotkey




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Default Sound Device changes on restart
I'm having a slight problem here, Windows 7 Ultimate. I'm set up with two monitors, the second with HDMI, but I have default sound as the speaker/headphone outputs on my motherboard. For some reason everytime I restart my computer it defaults to HDMI for audio and I need to switch it back, kinda...
Sound & Audio
hotkey to disable an audio device of choice
How would I add a hotkey to toggle on/off an audio device of choice in Windows 7 x64? Here is an image of Windows 7 sound dialog window > playback tab to audio devices. reason being: skype doesn't have a default audio device as an option so I switch between headphone (reciever) to speaker...
General Discussion
default sound device is disable
Good Day to all of you. I am a new here and was trying to search for may problem which could not find the related issue. I tried to change the default playback on my laptop but the option "set default" is disabled and could not be changed. Hence, please help how could have it enable, I have...
Sound & Audio
Mbox 2 + Windows 7 Default Sound Device
Hey everybody, So i was just wondering if anybody here could help me with this problem. I have a Digidesign Mbox 2 which i use as my external sound card for music production, i just upgraded from XP to Windows 7 64 bit and while the external sound card works for Pro-tools and my other audio...
Sound & Audio
How to set default sound playback device
Hi, I have system with multiple Sound playback devices. Most of the time it needs to be on the first entry in the list of devices (HDMI output with me). I'm looking for a way that when I have manually set it to another device in the list, and then shut down the pc that at the next boot it...
Sound & Audio
Changing default Sound Device
Is there any possibility of changing the sound device programatically in Windows 7? Or atleast to make the device as the default sound device during installation? In Vista, I could use SetupPreferredAudioDevice key in INF file to make it as default at the time of installation, but I could see...
Sound & Audio


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 16:04.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App