Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Toggle set default audio device in Windows 7.


  • Please log in to reply
18 replies to this topic
KeyOh
  • Members
  • 9 posts
  • Last active: Mar 20 2015 08:47 PM
  • Joined: 14 May 2009

Hi guys,

Thank you for all the scripting. I made some minor tweaks to support switching between 3 cards.

#F5::
 gosub AudioCardChanger
 return
;----------

AudioCardChanger:
 FileRead, CardNo, %ProgramFiles%\AutoHotkey\soundcardno.mvd
 
 If (CardNo = "") 
 {
  FileAppend, 1, %ProgramFiles%\AutoHotkey\soundcardno.mvd
  CardNo = 1
 }

 Run, mmsys.cpl
 Winhide,Sound
 WinWait,Sound

 If (CardNo = 1)
   ControlSend,SysListView321,{Down 1}
 If (CardNo = 2)
   ControlSend,SysListView321,{Down 2}
 If (CardNo = 3)
   ControlSend,SysListView321,{Down 3}

 ControlGet, Current, List, Selected, SysListView321
 TrayTip, Aktivt lydkort:,  %current%
 SetTimer, RemoveTrayTip, 1500

 ControlClick,&Set Default,Sound,,,,na
 sleep 50
 ControlClick,OK,Sound,,,,na
 sleep 50
 WinClose,Sound

 CardNo += 1

 If (CardNo = 4)
  CardNo = 1

 FileDelete, %ProgramFiles%\AutoHotkey\soundcardno.mvd
 FileAppend, %CardNo%, %ProgramFiles%\AutoHotkey\soundcardno.mvd
Return

Its easy to increase the number of cards:

Just add more if statements:

 If (CardNo = 2)
   ControlSend,SysListView321,{Down 2}
 If (CardNo = 3)
   ControlSend,SysListView321,{Down 3}

 If (CardNo = 4)
   ControlSend,SysListView321,{Down 4}

 If (CardNo = 5)
   ControlSend,SysListView321,{Down 5}

 

and change the number below to 1 higher than the amount of soundcards:

 If (CardNo = 6)
  CardNo = 1



fohrums
  • Members
  • 6 posts
  • Last active: Sep 30 2014 10:13 PM
  • Joined: 08 Feb 2014

This is what i'm using, instead (Windows 7 x64 Home):

 

#problem: when using this toggle script (i'm guessing because of ControlClick) upon a fullscreen application that's focused you will minimize that app and stay minimized. How is it possible to have it run in the background without focusing the window at all so that way I can prevent my fullscreen application (playing game) to be interupted?

; toggle speaker setup
^!s::

  switch := !switch

    If (switch)
        usePlaybackDevice(1)
    else
        usePlaybackDevice(2)
    return

 usePlaybackDevice(device) {
    Run, mmsys.cpl
    WinWaitActive, Sound ahk_class #32770
    ControlSend, SysListView321,{Down %device%}, Sound ahk_class #32770
    ControlClick, &Set Default, Sound ahk_class #32770
    WinClose, Sound ahk_class #32770
    Soundset, 50
    TrayTip, , % if device = 1 ? "Speakers" : "Headphones"
}


jhwilliams
  • New members
  • 2 posts
  • Last active: Aug 03 2015 06:43 PM
  • Joined: 03 Aug 2015

Hey guys.  I'm pretty new to AHK.  I studied this code and it mostly makes sense to me but I have one question. 

 

How did you find the run command, "mmsys.cpl"?  How did you know was the file you wanted to run?  Where is this information found? 

 

I would like to make some hotkeys that run other programs and I think adapting this code will help.

 

Thanks!



Soulsy
  • New members
  • 1 posts
  • Last active: Sep 03 2015 10:13 AM
  • Joined: 03 Sep 2015

Hey guys.  I'm pretty new to AHK.  I studied this code and it mostly makes sense to me but I have one question. 

 

How did you find the run command, "mmsys.cpl"?  How did you know was the file you wanted to run?  Where is this information found? 

 

I would like to make some hotkeys that run other programs and I think adapting this code will help.

 

Thanks!

 

There is a Microsoft resource here: https://support.micr...en-us/kb/192806

The ".cpl" indicates it is a control panel item. These files are located in '*\Windows\System32', just do a search for .cpl!