Sign in to follow this  
Followers 0
muh2k4

WinActivate + SetOnTop does not work

4 posts in this topic

#1 ·  Posted (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 :D

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 by muh2k4

Share this post


Link to post
Share on other sites



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..


_____________________________________________________________________________

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

:D, 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 :huggles:...

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).

#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 by KaFu

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 :D

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 by muh2k4

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0