muh2k4 Posted February 2, 2010 Share Posted February 2, 2010 (edited) Hello, I use Windows 7 and i wrote a script to change the default audio device. More precisely I wrote 3 for 3 devices. They are set on my G-Buttons of my G15 Keyboard. The scripts work, but if i have other Programs like Chrome running, the audio device window is not on top and the "Send" action is not be executed. The audio window opens, but it stays in the background and i need to open in manually via mouse or alt tap to get the send action executed. Even if I use "WinActivate" and "SetOnTop" the window does not get focused. I hope you understand my slappy English and want to help me get the audio device changed without always manually activating the audio window This is and Example of 1 of my Scripts. All 3 are very similar. Run("control mmsys.cpl") ;runs the audio windows WinActivate ("Sound", "Die folgenden Audiowiedergabegeräte sind installiert") ;activates it WinSetOnTop ("Sound", "Die folgenden Audiowiedergabegeräte sind installiert", 1) ;set it on top WinWaitActive("Sound") ;wait till its active Send("{HOME}") ;mark the wanted device ControlClick("Sound", "Die folgenden Audiowiedergabegeräte sind installiert", 1002) ;click "as standard" ControlClick("Sound", "Die folgenden Audiowiedergabegeräte sind installiert", 1) ;click "OK" Greetings, muh2k4 Edited February 2, 2010 by muh2k4 Link to comment Share on other sites More sharing options...
GodlessSinner Posted February 2, 2010 Share Posted February 2, 2010 Retrive a control ID with "Autoit Window Info" and use ControlSend to send what you need directly in window, and OnTop it's or not - it's doesn't matter.. _____________________________________________________________________________ Link to comment Share on other sites More sharing options...
KaFu Posted February 2, 2010 Share Posted February 2, 2010 (edited) , had the same problem switching sound from PC-Speakers to Amplifier for my HTPC... did some research and found out that MS does not provide a dll solution for the new Win7 sound system... failure by design... here's my solution, works most of the time ... Needs to be compiled in line to @OSArch (32 or 64bit), the last commented line calls icu.exe (see my sig) to restore my desktop settings. I call this script in combination with ATI Hotkey Switch, thus if you don't use it delete the first few lines dealing with the resolution (now in #cs-#ce). expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs $timer = TimerInit() While 1 Sleep(250) If "1600x1200" = @DesktopWidth & "x" & @DesktopHeight Then ExitLoop If TimerDiff($timer) > 10000 Then Exit WEnd #ce $iPID = Run("control mmsys.cpl", "", @SW_HIDE) $hWndSound = 0 $timer = TimerInit() While Not WinExists($hWndSound) Sleep(10) $hWndSound = WinGetHandle("[TITLE: Sound; CLASS: #32770]") If TimerDiff($timer) > 10000 Then Exit WEnd BlockInput(1) Sleep(1500) ControlSend($hWndSound, "", "", "{DOWN 2}") ; TV = 1 => DOWN 3 ; PC = 2 => DOWN 2 Sleep(300) ControlClick($hWndSound, "", "Button2") Sleep(500) WinClose($hWndSound) BlockInput(0) ;Run(@ScriptDir & "\icu.exe restore 1") Edited February 2, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
muh2k4 Posted February 2, 2010 Author Share Posted February 2, 2010 (edited) Thank you both so much. The ControlSend command and the Script Example made it work for me! Of course my script does not look anway like yours, but thanks for the ideas I do not now if its a bug, but if i use "WinWaitActive", my window is set to background and if I use "WintWaitNotActive" it is set to foreground. So I used the Timeout as 1 millisecond and the Timeout apperantly just begins to count, as soon as the window is loaded, so the Commands are sent to an loaded window with "ControlSend" and everything works just fine. It is a little bit tricky and maybe not well enough exlplained of me, but it works and thank you very much for it! Greetings, muh2k4 This is the script from above after editing: Run("control mmsys.cpl") WinWaitNotActive("Sound", "Die folgenden Audiowiedergabegeräte sind installiert", 1) ControlSend ("Sound", "", 1000, "{HOME}") ControlClick("Sound", "&Als Standard", 1002) ControlClick("Sound", "OK", 1) Edited February 2, 2010 by muh2k4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now