Jump to content

Noob needs help with DropDown list


Recommended Posts

Hello,

I'm Uwe, 55 years old and from Germany. Please excuse my bad English. English is not my native language. I have no experience in programming, scripts, etc. I would like to simply select an entry with AutoIt in a dropdown list. Actually ... :)
I'm on the road with Windows 10 and would like to select a source in the sound setting under Recording at the Realtek stereo mix (Picture 1). After much searching and reading, I found a script in a forum and modified this with trial and error to fit my needs.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiSlider.au3>
#include <GuiButton.au3>

;*********************************************
Func ConfigureStereoMix()
    WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)

    Send("^{TAB}")
    WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)

    ;TAB "Abhören". Hier klappt das Setzen / Auswahl in der DropDown Liste NICHT
    ControlCommand("[CLASS:#32770]", "", 1600, "SelectString", "Lautsprecher (GameDAC Game)") ; Do not work! Why?

    Send("^{TAB}")
    WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)

    Send("^{TAB}")
    WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)

    Send("^{TAB}")
    WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)

    ;TAB "Erweitert". Hier klappt das Setzen / Auswahl in der DropDown Liste. Nur zum Testen wird später entfernt.
    ControlCommand("[CLASS:#32770]", "", 1410, "SelectString", "2 Kanal, 16 Bit, 44100 Hz (CD-Qualität)") ; Works wonderful. Only for testing. Will be removed later

;Click the Ok button
    ControlClick("[CLASS:#32770]", "", 1)
    WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)
EndFunc
;*********************************************

;*********************************************
Func SetRecordingDeviceConfig()

    Dim $itemCount
    $itemCount = ControlListView("Sound", "", "SysListView321", "GetItemCount")
;Loop through items to configure the devices
    For $i = 0 to $itemCount - 1
    ;Select the item
        ControlListView("Sound", "", "SysListView321", "Select", $i)
        WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)

    ;Click the properties button to open the dialog and determine the device
        ControlClick("Sound", "", 1003)
        WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)

        Dim $var
    ;Get the string in the editbox
        $var = ControlGetText("[CLASS:#32770]", "", 1201)
        Switch $var
        Case "Stereomix"
            ConfigureStereoMix()
        Case Else
        ;Click Cancel to close the dialog
            ControlClick("[CLASS:#32770]", "", 2)
            WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)
        EndSwitch
    Next
EndFunc
;*********************************************

;*********************************************
;Show the sound dialog with the first tab (Playback) selected
Run("control mmsys.cpl,,0")
Opt("WinWaitDelay", 1000)
WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)
;*********************************************

;*********************************************
;Move to next tab (Recording) in dialog
Send("^{TAB}")
WinWait("[TITLE:Sound; CLASS:#32770]", "", 10)
;*********************************************

;*********************************************
;Call the function to set the Recording device configurations
SetRecordingDeviceConfig()
;*********************************************

;*********************************************
;Click the Ok button to close the dialog
ControlClick("Sound", "", 1)
;*********************************************

Checkbox and select an entry in another DropDown list (Picture 3) works wonderful, only in this DropDown list (Picture 2) it just will not work. Nothing is selected or set. I am at a loss and could use some help.

According to AutoIt Window Info, both lists differ only in the ID. List which does not work has the ID 1600 (picture 1a) and the list that works has the ID 1410 (picture 3a). Otherwise I can not find any differences. I have tried several things. Sorry, I do not know and I am lost.

Yours sincerely

Uwe

Bild1.jpg

Bild1a.jpg

Bild2.jpg

Bild3.jpg

Bild3a.jpg

Link to comment
Share on other sites

Hello Mr.  You can use controlcommand function to select a text in a combobox like this way:

ControlCommand("Window Title Here","","ComboBox1","SelectString","Here the combobox string to select")

 

Saludos

Link to comment
Share on other sites

Hi,

thank for your help. I have tried it your way. Result is the same. First DropDown list did not work. Second DropDown list work wonderful. I have tested so much hints that i found in other posts but nothing works. First DropDown list did nothing.

Link to comment
Share on other sites

@Uwe63  Hi - I tested first drop down.  I am getting the same problem as you but I found a way to save you. Replace line :

2 hours ago, Uwe63 said:

ControlCommand("[CLASS:#32770]", "", 1600, "SelectString", "Lautsprecher (GameDAC Game)") ; Do not work! Why?

with

opt ("MouseCoordMode",0) ; go into relative mode
ControlCommand("[CLASS:#32770]", "", 1600, "ShowDropDown", "")
Sleep (500)
MouseClick ("left",160,280,1) ; click 3rd selection
opt ("MouseCoordMode",1) ; return into absolute mode

Seems that this DropDown only responds to mouse move and click.  I tried with keyboard, doesn't work either.  Adjust the mouse position to the selection you want.

Link to comment
Share on other sites

Hi,

Nine thank you for your testing and input. Sorry can't use your solution because the device position in the DropDown list changes with every computer start / reboot. Crappy device driver i think. I started with AutoHotKey and had to move on to AutoIt because of this failure.

 

Rex thank you, but SSD is not what i need. I like to set a sound mirror device in the "Stereomix" TAB (i think it's called "what you hear" in english).

 

So looks like it's not possible with AutoIt or to complicated for me.

Hopefully some other expert comes the way and find a solution.

 

Link to comment
Share on other sites

There is always a possible solution.  But the more general you want it to get, the more it's get complicated. It is still possible to read the dropdown and choose the right row.  And then infer the right mouse position.  It all depends how important it is for you...

Link to comment
Share on other sites

You can use the following:

#include <Debug.au3> ;~ Add to the top of your list, so we can use _DebugArrayDisplay() function
Replace: _ArrayDisplay with _DebugArrayDisplay
Replace: _SwitchToDevice function with the following:

Func _SwitchToDevice($sId, $eRoles = 0)
    Local $oPolicyConfig = ObjCreateInterface($sCLSID_CPolicyConfigClient, $sIID_IPolicyConfig, $tagIPolicyConfig)
    Local $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eConsole)
    If $hResult = $S_OK Then $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eRoles)
    Return $hResult = $S_OK
EndFunc ;==>_SwitchToDevice

Now run the script and from the _DebugArrayDisplay you should now be able to see all Playback and Recording devices on your system, you'll need to use something like _ArraySearch to find your preferred audio device.  You'll then use the 2 column item the $sID with _SwitchToDevice to change your settings

For example to set the default Playback/Recording device for my headphones for both playback and recording I would use::

_SwitchToDevice("{0.0.0.00000000}.{bd334a69-5528-4f8d-a85d-8035c14686e5}", 0) ;~ This sets the default playback device
    _SwitchToDevice("{0.0.1.00000000}.{c37b1c2e-5c21-4988-a865-fc44938e5d6b}", 2) ;~ This sets the default recording device

For the configuration of the device you should be able to capture:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio

Make your changes and then recapture the key above and look at the differences using something like WinMerge you should be able to add the (changed values or a subset of those changed values into your script using RegWrite.  Just make sure you're familiar with Registry otherwise you may bugger you system.

Link to comment
Share on other sites

This will set to the device of your choice, no matter how many devices the computer has :

Opt("MouseCoordMode", 0) ; Set to relative mode
Local Const $Search = "Lautsprecher"
Local $x = 160, $y = 257, $Height = 13 ; position of the first device in dropdown
Local $s, $prev = "", $i = 0
Do
    ControlCommand("[CLASS:#32770]", "", 1600, "ShowDropDown", "")
    Sleep(500)
    MouseClick("left", $x, $y + $i * $Height, 1)
    $i += 1
    Local $s = ControlGetText("[CLASS:#32770]", "", 1600)
    If $prev = $s Then ExitLoop  ; in case the searched device doesn't exist
    $prev = $s
Until $Search = StringLeft($s, StringLen($Search))

MsgBox($MB_SYSTEMMODAL, "", $s)
Opt("MouseCoordMode", 1) ; Return to absolute mode

Tested and working :)

Edited by Nine
Link to comment
Share on other sites

Even better :

#include <GuiComboBox.au3>
#include <Array.au3>

Local Const $Search = "Lautsprecher"
Local $x = 160, $y = 257, $Height = 13 ; position of the first device in dropdown
Local $hCtrl = ControlGetHandle("[CLASS:#32770]", "", 1600)
Local $arr = _GUICtrlComboBox_GetListArray($hCtrl)
;_ArrayDisplay ($arr)
Local $Ind = _ArraySearch($arr, $Search, 0, 0, 0, 1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Device not found")
ControlCommand("[CLASS:#32770]", "", 1600, "ShowDropDown", "")
Sleep(500)
Opt("MouseCoordMode", 0)     ; Set to relative mode
MouseClick("left", $x, $y + ($Ind-1) * $Height, 1)
Opt("MouseCoordMode", 1)     ; Return to absolute mode

MsgBox($MB_SYSTEMMODAL, "", ControlGetText("[CLASS:#32770]", "", 1600))

 

Link to comment
Share on other sites

Even more better :)

#include <GuiComboBox.au3>
#include <Array.au3>

Local Const $Search = "Haut-parleurs"
Local $hCtrl = ControlGetHandle("[CLASS:#32770]", "", 1600)
Local $arr = _GUICtrlComboBox_GetListArray($hCtrl)
Local $Ind = _ArraySearch($arr, $Search, 0, 0, 0, 1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Device not found")
_GUICtrlComboBox_SetCurSel ($hCtrl,$Ind-1)

Seems that _GUICtrlComboBox_* are working fine with this particular control. 

Edited by Nine
Link to comment
Share on other sites

Hello Nine,

many many thanks. Your script works wonderfull!

 

Your script is way better then my solution. My solution was a mix from Subz script and your mouse move script. It was a horrible script but did what i want. :)

 

Once again, many thanks.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...