Select text from prompt and select the proper option

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Eppsilan
Posts: 3
Joined: 10 May 2017, 11:01

Select text from prompt and select the proper option

10 May 2017, 11:28

Hello Everyone,

I have written an AHK script that configures an application for me. This is my first script, and I tried to keep it as basic as possible. I have run into a snag that I have not been able to figure out.

In the attached screenshot. There are 2 options: New File and STT Matching. I would like my script to read the proper "Title" and select the proper option.

For Ex: If I am setting up the "New File" I want it to select the "New File", not the "STT Matching" one. Then vice versa.

The order these create themselves is not always the same. Sometimes its reversed. I have tried just a simple "Send, {Tab}{Down}" and "Send, {Tab}{Down}{Down}" (In the second portion) but that does not work all the time. I am not able to "Type" in this window nor am I able to tab to the "Title" and organize it.

I have tried searching the forums and Google, but I am honestly not sure where to start with this.

Any help would be greatly appreciated.

Thank You!!!
Attachments
1.PNG
1.PNG (31.29 KiB) Viewed 3176 times
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Select text from prompt and select the proper option

10 May 2017, 11:53

SendMessage/PostMessage ?
Control ... ??

BTW, out of curiosity what's the name of that program??
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Select text from prompt and select the proper option

10 May 2017, 12:49

If that control is a standard SysListView32 control, then the following code should get the row number of the row containing 'New File'. You can use that to determine how many key presses to send.

Code: Select all

q:: ;get 1-based index of listview item that contains text
ControlGet, vText, List, Col2, SysListView321, A
vCount := ""
Loop, Parse, vText, `n
	if (A_LoopField = "New File")
	{
		vCount := A_Index
		break
	}
MsgBox, % vCount
return
[EDIT:] 0-based index v. 1-based index: 0-based means the first item is 'item 0', 1-based means the first item is 'item 1'.

If the right row is already focused, you wouldn't have to change the listview item selection:

Code: Select all

w:: ;get text of focused listview item
ControlGet, vText, List, Focused Col2, SysListView321, A
MsgBox, % vText
return
Use AutoHotkey's window spy, to retrieve the ClassNN for that control that looks like a listview, to check if it's SysListView321.

I was working on an LVSetSel function to set the focus/selection in a listview control, which I may finish soon, and then post here.

[EDIT:] One way to change the selection is:

Code: Select all

e::
ControlSend, SysListView321, {Down}, A
return
[EDIT:] Btw for some listviews:
ControlGet
https://www.autohotkey.com/docs/commands/ControlGet.htm
Some applications store their ListView text privately, which prevents their text from being retrieved.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Eppsilan
Posts: 3
Joined: 10 May 2017, 11:01

Re: Select text from prompt and select the proper option

10 May 2017, 14:37

BoBo - I am working with OMTool Accuroute

Jeeswg - Thank you for the response. The code works pretty well. Now I want to make to so, if it reads "New File" It will do a {Tab}{Tab}{Enter} or if it reads "STT Matching" it will do {Down}{Tab}{Tab}{Enter}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Select text from prompt and select the proper option

10 May 2017, 14:53

I've written some code that literally does what you asked, but I've written another version that I think may be more reliable.

Basically the loop is to double-check that after changing the selection, you have the selection you want. A pause, which may or not be useful there, I have left commented out.

I've guessed that the 'Select' button is 'Button1'.

Code: Select all

q::
ControlGet, vText, List, Focused Col2, SysListView321, A
if (vText = "New File")
	Send {Tab 2}{Enter}
else
	Send {Down}{Tab 2}{Enter}
return

w::
WinGet, hWnd, ID, A
Loop
{
	;if !(A_Index = 1)
	;	Sleep 100
	ControlGet, vText, List, Focused Col2, SysListView321, % "ahk_id " hWnd
	if (vText = "New File")
		break
	else
		ControlSend, SysListView321, {Down}, % "ahk_id " hWnd
}
ControlClick, Button1, % "ahk_id " hWnd
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Eppsilan
Posts: 3
Joined: 10 May 2017, 11:01

Re: Select text from prompt and select the proper option

13 May 2017, 16:45

You are absolutely amazing! Thank you for your help!!!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Select text from prompt and select the proper option

21 Oct 2017, 23:42

I managed to get the Acc functions to focus and select an item in an external listview control.

Code: Select all

;[Acc functions]
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

q:: ;focus/select a listview item (e.g. a file/folder on Desktop: tested on Windows 7)
vNeedle := "New Folder"
WinGet, hWnd, ID, A
ControlGet, hCtl, Hwnd,, SysListView321, A
if !hCtl
	return
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
vMaxX := 0, vMaxY := 0
Loop, % oAcc.accChildCount
{
	try
		vName := oAcc.accName(A_Index)
	catch
		continue
	if (vName = vNeedle)
	{
		;SELFLAG_TAKESELECTION := 0x2 ;SELFLAG_TAKEFOCUS := 0x1
		oAcc.accSelect(0x3, A_Index)
		break
	}
}
oAcc := ""
;without doing WinActivate, we are stuck with the listview as the active window (tested on Windows 7)
WinActivate, % "ahk_id " hWnd
return
Note:
An example of a listview control for testing is Desktop, although to select files in Explorer windows and Desktop I would use the functions here instead:
Explorer window interaction (folder windows/Desktop, file/folder enumeration/selection/navigation/creation) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=35041

Link:
SELFLAG Constants (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: makdc96, RandomBoy, Rohwedder and 176 guests