AutoHotkey Community

It is currently May 25th, 2012, 7:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 85 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
PostPosted: February 21st, 2005, 6:21 am 
I'm looking for a way to automate the procedure of switching from one audio device to another. Typically, this involves going to the control panel --> sound and audio devices --> audio --> default device --> etc etc

Is there any way to create a script that will automatically change the device, run a particular program (for example, tv tuner software that is incompatible with my USB audio out), then change the audio device back to what it was originally...?

Any suggestions or help would be very much appreciated!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2005, 8:36 am 
Offline

Joined: February 10th, 2005, 7:51 pm
Posts: 14
Location: Tallinn, Estonia
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.

Code:
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, Sounds and Audio Devices Properties
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2005, 8:54 am 
Quote:
SoundSet
--------------------------------------------------------------------------------
Changes various settings of a sound device (master mute, master volume, etc.)

SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]

If this parameter is omitted, it defaults to 1 (the first sound device), which is usually the system's default device for recording and playback. Specify a number higher than 1 to operate upon a different sound device.


Might be of interest.
8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2005, 10:36 am 
Offline

Joined: February 10th, 2005, 7:51 pm
Posts: 14
Location: Tallinn, Estonia
Quote:
SoundSet
--------------------------------------------------------------------------------
Changes various settings of a sound device (master mute, master volume, etc.)

SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]

If this parameter is omitted, it defaults to 1 (the first sound device), which is usually the system's default device for recording and playback. Specify a number higher than 1 to operate upon a different sound device.


SoundSet only changes volume etc. of a selected device, but it does not change which device is active.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2005, 6:58 pm 
Great script procyon! Thx for sharing.
Sidenote tho, the !A-command is irrelevant as the simple enter-press does apply aswell as close the window. Makes it all slightly faster :)
Also, why use the sleep-command when you will be waiting for the window to emerge anyway?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2007, 12:28 pm 
Offline

Joined: September 24th, 2007, 9:05 am
Posts: 41
Awsome Script!!

I had always wanted to do this, but i had no idea about this part
Code:
Run, mmsys.cpl


Thanks Alot for posting this.

I changed it a Lil bit on mine

Code:
Send, ^{Tab 2}
Sleep, 100


High Five!!

_________________
Bigrob

L337 Speak - A Ventrilo Client Side program

Winamp Sound Changer - Change Audio Output on the Fly!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2008, 1:19 am 
Offline

Joined: July 15th, 2006, 1:30 am
Posts: 48
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:
Code:
; 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.

_________________
One hotkey to rule them all!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2008, 3:13 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
Thanks, this will help me when I get around to making a script that will detect when I plug my HDMI cable into my laptop and change the default playback device for me! Too bad I'm so lazy or I'd have done it by now :oops:

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 30th, 2008, 1:39 am 
Offline

Joined: December 30th, 2008, 1:01 am
Posts: 2
Thanks Xavier! @(^_^)@ Exactly what I needed for generating multiple Audio sources from an HTPC for a multi source & multi room audio system.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2009, 4:42 am 
Im trying to do the same thing in vista but using the mute button on my first gen g15 keyboard. I'm also a noob with scripts any help would be greatly appreciated!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2009, 4:43 am 
Edit: Im only using one soud device but different output (digital out / headphones)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2009, 7:12 am 
the registry key "HKEY_CURRENT_USER\ Software\Microsoft\Multimedia\Sound Mapper\Playback" doesn't exist
i'm using xp sp3


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2009, 4:14 pm 
I think this is pretty efficient. The sound dialog pops up, but for a split second only.

Here I've set it to F5 setting the first device on the list as default and F6 setting the second as default. Tweak it as needed.

Code:
#F5::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down}
    ControlClick,&Set Default
    ControlClick,OK
    return
#F6::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down 2}
    ControlClick,&Set Default
    ControlClick,OK
    return


Report this post
Top
  
Reply with quote  
PostPosted: September 21st, 2009, 3:54 am 
Offline

Joined: September 21st, 2009, 3:48 am
Posts: 1
I just updated to windows 7 and needed a toggle version of this script. I mixed and matched what I had with the above posts and came up with this.

This will set the first device active if it isn't already.
If the first device is active then it will activate the 3rd device.

Additionally once a device is picked it plays a sound so you know which device is selected.

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 24th, 2009, 12:00 am 
Offline

Joined: March 29th, 2006, 12:28 am
Posts: 17
Unfortunately playing with the registry didn't help me. I guess it is because I have a single sound card and I'm just trying to switch between 2 ports (front and back). So I went back to use the following GUI automation.

The function below takes "device" as it appears in mmsys.cpl and looks for it in the combobox. If it finds it it changes the device and returns true. Otherwise it returns false.

I do use the registry first, however, to check whether the current device is the one we are trying to switch to since, while setting the registry value doesn't change the real sound device, changing the sound device DOES reflect in the registry.

Code:
ChangeSoundDevice(device)
{
   window=Sounds and Audio Devices Properties
   success := false

   RegRead, registryDevice, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback
   registryDevice = %registryDevice%
   if registryDevice = %device%
   {
      success := true
   }
   else
   {
      Run control mmsys.cpl`,`,2
      WinWait, Sounds and Audio Devices Properties,,5

      ControlSend,ComboBox1,{Home},%window%
      CurrentDevice=
      Loop
      {
         ControlGetText,outputs,ComboBox1,%window%
         ; Trimming spaces
         outputs = %outputs%

         if outputs = %device%
         {
            success := true
            break
         }
         else if outputs<>%CurrentDevice%
         {
            ;MsgBox, Not equal: "%CurrentDevice%" <> "%outputs%"
            CurrentDevice = %outputs%
         }
         else
         {
            ;MsgBox, Equal: "%CurrentDevice%" == "%outputs%"
            OSD("Device not found:" . device)
            break
         }

         ControlSend,ComboBox1,{Down},%window%
      }

      Send ^{Enter}
   }
   return success
}


Thanks,
Vitaly

P.S The code works in XP, I assume some changes would be needed under Vista/7

_________________
Vitaly


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 85 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Baidu [Spider], dra, engunneer, rbrtryn, toddintr, vsub, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group