How to choose a string from a DropDownList Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

How to choose a string from a DropDownList

24 May 2018, 03:14

I am trying to set a control in Notepad++, namely the Font name in the Style Configurator. It seems that there are two commands to do the job: Control and GuiControl. I tried both, but none changes the chosen string:

Code: Select all

#IfWinActive ahk_class Notepad++
+!1::
+!2::
	; Call Style Configurator:
	Send !t{down}{enter}
	
	; give control plenty of time to build up:
	sleep 3000
	
	; choose the string:
	if (A_ThisHotkey="+!1")
		Control ChooseString, Courier New, ComboBox2 
	else
		GuiControl, ChooseString, ComboBox2, Courier New 
	Return
BTW, this led to the more general question “Graphical User Interface” vs “Window Controls”.
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: How to choose a string from a DropDownList  Topic is solved

24 May 2018, 05:35

Hello Micromegas,
Graphical User Interface GuiControl only works in windows created with AHK

Try this

Code: Select all

#IfWinActive ahk_class Notepad++
+!1::
+!2::
DDLChoice := A_ThisHotkey="+!1" ? "Arial" : "Courier New"
Send !t{down}{enter}   ; ;Call Style Configurator:
WinWaitActive ahk_class #32770 ahk_exe notepad++.exe
ControlFocus, ComboBox2, ahk_class #32770 ahk_exe notepad++.exe
Control, ChooseString, % DDLChoice, ComboBox2 ,A
Return
Donec Perficiam
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: How to choose a string from a DropDownList

24 May 2018, 06:33

Thanks, this works!
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: How to choose a string from a DropDownList

24 May 2018, 06:39

ControlFocus is not necessary
Donec Perficiam
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: How to choose a string from a DropDownList

24 May 2018, 07:10

jmeneses wrote:ControlFocus is not necessary
Oh, indeed! So the A in Control, ChooseString, % DDLChoice, ComboBox2 ,A gets its reference from WinWaitActive not from ControlFocus. BTW, it also works with Sleep instead of WinWaitActive, (in which case one has to set the WinTitle, since there's no A). (Not that that's preferable; I only wanted to pinpoint what fixed the problem. In fact, I had WinWaitActive originally, but thought the problem might be caused by the dropdown list needing more time.)
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: How to choose a string from a DropDownList

24 May 2018, 08:03

I prefer WinWaitActive because the window class #32770 is displayed more or less quickly according to the speed of the CPU, load of processes and more.
Donec Perficiam
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: How to choose a string from a DropDownList

25 May 2018, 03:26

jmeneses wrote:I prefer WinWaitActive because the window class #32770 is displayed more or less quickly according to the speed of the CPU, load of processes and more.
Of course; it was only for testing that I let it Sleep in the first place. I just had wanted to rule out the possibility that WinWaitActive fired before the DropDownList was fully populated. And then I wanted to minimize the differences between your code and mine so I could pinpoint the deciding functional change.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], haomingchen1998, mikeyww and 246 guests