topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 3:30 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: DONE: A shortcut/hotkey to switch between audio devices?  (Read 54992 times)

moerl

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 404
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #25 on: April 12, 2006, 04:48 PM »
Hmmmm.. ok. I downloaded the script file, double clicked it while Realtek Audio is active, and while I do see the Audio properties popup and disappear right away, nothing changes. The device is not switched.

This is the script I used:

SetTitleMatchMode, Slow

Run, RunDll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,2
WinWait,ahk_class #32770

IfWinActive, ahk_class #32770, RealTek AC97 Audio
     send, {alt down}d{alt up}s{enter}
else
     send, {alt down}d{alt up}r{enter}

moerl

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 404
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #26 on: April 12, 2006, 04:52 PM »
I just found out something else as well that's interesting. If I have the system set to use the Sennheiser headset and THEN execute the AHK script, it works EXACTLY as desired, switching the used sound device from the headset to the system's soundcard, Realtek Audio. However, if Realtek is selected first and the script is executed, no change occurs. In other words, the script works exactly as it should, but only one way...

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,066
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #27 on: April 12, 2006, 06:08 PM »
Looks like the ahk_class parameter is set incorrectly ... I'll see if I can work out what it should be tomorrow.

moerl

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 404
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #28 on: April 12, 2006, 06:57 PM »
Thanks :). I wish I could do it myself but I don't even have a damn clue how that super simple script I have now works... so... thanks.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #29 on: April 12, 2006, 07:01 PM »
The problem is that it is never noticing that the string " RealTek AC97 Audio" is in the window.
Try changing that line to "IfWinActive,ahk_class #32770,Realtek". I don't think that'll solve it, but it's worth trying.
Still, if that doesn't work, you can always make 2 different scripts, as Carol mentioned. Or, if you use it very often, make one script, with hotkeys.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,066
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #30 on: April 12, 2006, 07:05 PM »
This version seems to work for me (see attached zip)

SetTitleMatchMode, Slow

Run, RunDll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,2
WinWait, Sounds and Audio Devices Properties

 IfWinActive, Sounds and Audio Devices Properties, RealTek AC97 Audio
     send, {alt down}d{alt up}s{enter}
 else
     send, {alt down}d{alt up}r{enter}
« Last Edit: April 12, 2006, 07:07 PM by Carol Haynes »

moerl

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 404
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #31 on: April 12, 2006, 07:37 PM »
This version seems to work for me (see attached zip)

SetTitleMatchMode, Slow

Run, RunDll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,2
WinWait, Sounds and Audio Devices Properties

 IfWinActive, Sounds and Audio Devices Properties, RealTek AC97 Audio
     send, {alt down}d{alt up}s{enter}
 else
     send, {alt down}d{alt up}r{enter}
-Carol Haynes (April 12, 2006, 07:05 PM)
It behaves just the same way as I described earlier. When I have the Sennheiser headset set, this script can switch it to Realtek Audio. However, if Realtek Audio selected, it is not able to switch it to the Sennheiser headset. I wonder why! I mean.. it does work perfectly in one direction... just not in the other :/

moerl

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 404
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #32 on: April 12, 2006, 07:41 PM »
The problem is that it is never noticing that the string " RealTek AC97 Audio" is in the window.
Try changing that line to "IfWinActive,ahk_class #32770,Realtek". I don't think that'll solve it, but it's worth trying.
Still, if that doesn't work, you can always make 2 different scripts, as Carol mentioned. Or, if you use it very often, make one script, with hotkeys.
Oh my... YOU DID IT! Your suggestion fixed the problem! It works now, in both directions :D:D:D. Brilliant! Thank you very much. Thanks to everybody else trying to help as well. Just awesome. Wow ;)

AHK is sweet. Now only to figure out how the hell to use it, and I'll be set!

While I'm at it.. how do I set a hotkey for scripts? And does AutoHotKey itself have its own GUI.. if so, how can it be accessed? I do have an entry for AHK on the start menu, but when I start AutoHotKey it starts with the default INI file and nothing really happens from what I could tell. It just opens the ini file in text-editing mode in notepad.

moerl

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 404
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #33 on: April 12, 2006, 07:45 PM »
Oops nevermind.. when I start it from the start menu, I get the AHK icon in the system tray and can access it from there. Not that the window that opens makes any sense to me whatsoever, but at least it's working. Of course I have to read the documentation if I want to understand it, and I can't wait to get to that, but I have no time to do that now.

Again, thanks so much to all of you for trying to help.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,066
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #34 on: April 12, 2006, 07:49 PM »
If you create a shortcut for the script (rather than running it directly) and then right click on the shortcut you can set a global hotkey for that shortcut. Then you should be able to toggle with a single hotkey press to your hearts content ;)

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #35 on: April 12, 2006, 07:54 PM »
Oh my... YOU DID IT! Your suggestion fixed the problem! It works now, in both directions :D:D:D. Brilliant! Thank you very much. Thanks to everybody else trying to help as well. Just awesome. Wow ;)
Great, that means that the problem was related with that string, mos probably, it was looking for " Realtek" instead of "Realtek" (notice the preceding space). Anyways, good to know it's working.

AHK is sweet. Now only to figure out how the hell to use it, and I'll be set!
It took me one week to start making great stuff, and one month to know almost everything there is about it. Don't worry, it's really fast to learn.

While I'm at it.. how do I set a hotkey for scripts? And does AutoHotKey itself have its own GUI.. if so, how can it be accessed? I do have an entry for AHK on the start menu, but when I start AutoHotKey it starts with the default INI file and nothing really happens from what I could tell. It just opens the ini file in text-editing mode in notepad.
AHK is a scripting language, that means there is no gui, because it's not a "real" program. I'd say the best place for you to start is the help file, which is an exelent resource, and has tuturials on how to do the basic stuff.
The help file is so good, that it's a constant reference, even for everyone that knows how to program in AHK. You should have a good look at it, it'll take out all your doubts ;)

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #36 on: April 12, 2006, 08:39 PM »
i'm glad to see that things picked up while i was not around. :up: amazingly, it was solved in just 4hrs 45mins... ;)
i think now is a good time to move this topic to "Finished Programs" on Coding Snacks.

...but when I right-click the desktop and choose NEW SHORTCUT the window that appears asks me for the file's location to which I want to create a shortcut. I can't just drop the code in that line :/

microsoft, in their infinite wisdom, have disabled the right-click menu in the "New Shortcut" dialog but you can press Control-V to paste the command. since you have already have a working script, this is just some additional info for the future...

moerl

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 404
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #37 on: April 12, 2006, 08:45 PM »
i'm glad to see that things picked up while i was not around. :up: amazingly, it was solved in just 4hrs 45mins... ;)
i think now is a good time to move this topic to "Finished Programs" on Coding Snacks.

...but when I right-click the desktop and choose NEW SHORTCUT the window that appears asks me for the file's location to which I want to create a shortcut. I can't just drop the code in that line :/

microsoft, in their infinite wisdom, have disabled the right-click menu in the "New Shortcut" dialog but you can press Control-V to paste the command. since you have already have a working script, this is just some additional info for the future...
Nono.. I didn't mean that. I know the paste command, of course, and never use the mouse. I meant that the dialog that shows up does not accepts commands. It wants a file path for the file you want to create the shortcut for. I did try pasting the command and clicking next and it just told me "Can't find file "Run"" or something like that, when "Run" was the first word of the command...
But yeah, the problem is solved. This is just a side discussion :)

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #38 on: April 12, 2006, 08:58 PM »
a'ah, i see... ok then use the full path to runDll32.exe, which should be in the system32 folder...

C:\Windows\System32\RunDll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,2
- or -

%windir%\System32\RunDll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,2

hmm.. maybe, i'll post a new topic containing all these handy short-cuts. :-\
now, if only i could find them...

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,260
    • View Profile
    • Donate to Member
Re: A shortcut/hotkey to switch between audio devices?
« Reply #39 on: April 13, 2006, 02:08 AM »
It works now, in both directions :D
Then please post the full code here for others to easily see it. Just click on the "#" above.

wr975

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 369
    • View Profile
    • Donate to Member
Re: DONE: A shortcut/hotkey to switch between audio devices?
« Reply #40 on: April 13, 2006, 02:31 AM »
Then please post the full code here for others to easily see it

Here's the working AHK script. Four people wrote on it, thanks to everyone involved!  :Thmbsup:


SetTitleMatchMode, Slow

Run, RunDll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,2
WinWait,ahk_class #32770

IfWinActive, ahk_class #32770,RealTek AC97 Audio
     send, {alt down}d{alt up}s{enter}
else
     send, {alt down}d{alt up}r{enter}
« Last Edit: April 13, 2006, 02:32 AM by wr975 »

DesertEagle

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 16
    • View Profile
    • Code Sector
    • Donate to Member
Re: DONE: A shortcut/hotkey to switch between audio devices?
« Reply #41 on: June 22, 2006, 07:35 PM »
Take a look at Audio Sliders (http://www.codesector.com/mixer.asp), it can change default playback and recording devices with single click on its tray icon.

zYx

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 2
    • View Profile
    • Donate to Member
Re: DONE: A shortcut/hotkey to switch between audio devices?
« Reply #42 on: November 30, 2008, 03:34 PM »
Hi,

how do I do it in windows vista?

Cheers
« Last Edit: November 30, 2008, 03:35 PM by zYx »

Ryan_S

  • Participant
  • Joined in 2009
  • *
  • Posts: 6
    • View Profile
    • Donate to Member
Re: DONE: A shortcut/hotkey to switch between audio devices?
« Reply #43 on: January 02, 2009, 09:19 PM »
I thought I'd add a script here for changing the device in Vista. I needed this for my XPS1530 for switching between the HDMI output and the speakers.

I had to write it in AutoIT because AutoHotKey doesn't support working with the SysListView directly, and I'm not a huge fan of sending keystrokes. I also couldn't find the registry keys in Vista. Seems MS has moved those.

Code: AutoIt [Select]
  1. Run("c:\windows\system32\control.exe mmsys.cpl")
  2.  
  3. WinWaitActive("Sound")
  4.  
  5. ControlListView("Sound", "", "SysListView321", "Select", 0) ;Select the first device in the list
  6. $result = ControlCommand("Sound", "", "Button2", "IsEnabled", "") ;checks if Set As Default button is enabled
  7. If $result Then
  8.         ;if Set As Default is enabled we can enable this device
  9.         ControlClick("Sound",  "", "Button2") ;Click Set As Default
  10.         ControlClick("Sound", "", "Button4") ;Click OK
  11.         Traytip("Audio Out", "Speakers / Headphones selected", 5, 1)
  12.         Sleep(5000)
  13.         Exit
  14.  
  15. ControlListView("Sound", "", "SysListView321", "Select", 1) ;select the second device in the list
  16. $result = ControlCommand("Sound", "", "Button2", "IsEnabled", "") ;checks if Set As Default button is enabled
  17. If $result Then
  18.         ;if Set As Default is enabled we can enable this device
  19.         ControlClick("Sound",  "", "Button2") ;Click Set As Default
  20.         ControlClick("Sound", "", "Button4") ;Click OK
  21.         Traytip("Audio Out", "HDMI selected", 5, 1)
  22.         Sleep(5000)
  23.         Exit
« Last Edit: January 02, 2009, 09:30 PM by Ryan_S »