how to click the first item in a listview?

Get help with using AutoHotkey and its commands and hotkeys
woshichuanqilz72
Posts: 112
Joined: 05 Oct 2015, 21:23

how to click the first item in a listview?

24 Nov 2017, 10:55

I find a listview in a window how to click the first row of it?

I think use controlclick by pos is not a good idea.
User avatar
jeeswg
Posts: 5939
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to click the first item in a listview?

24 Nov 2017, 13:15

To select the first item in a listview:

Code: Select all

q::
ControlSend, SysListView321, {Home}, A
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
woshichuanqilz72
Posts: 112
Joined: 05 Oct 2015, 21:23

Re: how to click the first item in a listview?

27 Nov 2017, 00:32

jeeswg wrote:To select the first item in a listview:

Code: Select all

q::
ControlSend, SysListView321, {Home}, A
return
hi bro thanks for your reply, it worked. Thank you.

I check the help doc and make this, you code works fine.

But Postmessage don't work why is that?

Code: Select all

PostMessage, 0x185, 1, -1, ListBox1, WinTitle  ; Select all listbox items. 0x185 is LB_SETSEL.

ControlSend, hh_kwd_vlist1, {Home}, AutoHotkey Help
User avatar
jeeswg
Posts: 5939
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to click the first item in a listview?

27 Nov 2017, 01:12

The hh_kwd_vlist (HTML Help) control for AutoHotkey Help (AutoHotkey.chm).

What type of control is it?
- AFAIK it is not a listbox or a listview control, at least, when I tried to count the items, it didn't work.

How to change the selection?
- Type the first few characters of the search term into the Edit control.
- Use up/down, PgUp/PgDn, home/end on the control.
- Use ControlClick or Acc to click the nth visible item.

For getting the text:
- I tried getting the text with Acc, which worked, but only received the text for visible rows.
- I found an old script I'd done, it kept pressing down, to navigate to the next item, and retrieved the text from the Edit control, so that's the best script I have for retrieving the text.

I wouldn't mind knowing a bit more about the control, but right now that's what I have. The only additional thing I might do is use a window spy like Winspector or Microsoft Spy++ to check the messages it receives. Cheers.

Code: Select all

q:: ;hh_kwd_vlist control - AutoHotkey Help (AutoHotkey.chm)
;not a listbox or a listview
ControlGet, hCtl, Hwnd,, hh_kwd_vlist1, A
MsgBox, % SendMessage(0x18B, 0, 0,, "ahk_id " hCtl) ;LB_GETCOUNT := 0x18B
MsgBox, % SendMessage(0x1004, 0, 0,, "ahk_id " hCtl) ;LVM_GETITEMCOUNT := 0x1004

;didn't work
;ControlGet, vText, List,,, % "ahk_id " hCtl
;MsgBox, % vText

;did work
ControlSend,, {Home}, % "ahk_id " hCtl
return

w:: ;autohotkey help (html help) - get text from list - simple method
;get text from hh_kwd_vlist control via Edit control
ControlGet, hCtl, Hwnd,, Edit1, A
vOutput := ""
;there were 924 items last time I tried
Loop, 2000
{	ControlGetText, vText,, % "ahk_id " hCtl
	vOutput .= vText "`r`n"
	if (vText = "{Blind}")
		break
	SendInput, {Down}
	vText2 := vText
	Loop, 1000
	{
		ControlGetText, vText,, % "ahk_id " hCtl
		if !(vText = vText2)
			break
		Sleep, 10
	}
}
Clipboard := vOutput
MsgBox, % "done"
return

;==================================================

SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
    local MsgReply
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    MsgReply := (ErrorLevel = "FAIL") ? "" : ErrorLevel
    ErrorLevel := (ErrorLevel = "FAIL")
    return MsgReply
}

Code: Select all

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

e:: ;autohotkey help (html help) - get text from list - using Acc
;warning: only gets visible rows
ControlGet, hCtl, Hwnd,, hh_kwd_vlist1, A
vOutput := ""
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
Loop, % oAcc.accChildCount
	try vOutput .= oAcc.accName(A_Index) "`r`n"
vOutput := SubStr(vOutput, 1, -2)
Clipboard := vOutput
MsgBox, % "done"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
woshichuanqilz72
Posts: 112
Joined: 05 Oct 2015, 21:23

Re: how to click the first item in a listview?

29 Nov 2017, 08:51

jeeswg wrote:The hh_kwd_vlist (HTML Help) control for AutoHotkey Help (AutoHotkey.chm).

What type of control is it?
- AFAIK it is not a listbox or a listview control, at least, when I tried to count the items, it didn't work.

How to change the selection?
- Type the first few characters of the search term into the Edit control.
- Use up/down, PgUp/PgDn, home/end on the control.
- Use ControlClick or Acc to click the nth visible item.

For getting the text:
- I tried getting the text with Acc, which worked, but only received the text for visible rows.
- I found an old script I'd done, it kept pressing down, to navigate to the next item, and retrieved the text from the Edit control, so that's the best script I have for retrieving the text.

I wouldn't mind knowing a bit more about the control, but right now that's what I have. The only additional thing I might do is use a window spy like Winspector or Microsoft Spy++ to check the messages it receives. Cheers.

Code: Select all

q:: ;hh_kwd_vlist control - AutoHotkey Help (AutoHotkey.chm)
;not a listbox or a listview
ControlGet, hCtl, Hwnd,, hh_kwd_vlist1, A
MsgBox, % SendMessage(0x18B, 0, 0,, "ahk_id " hCtl) ;LB_GETCOUNT := 0x18B
MsgBox, % SendMessage(0x1004, 0, 0,, "ahk_id " hCtl) ;LVM_GETITEMCOUNT := 0x1004

;didn't work
;ControlGet, vText, List,,, % "ahk_id " hCtl
;MsgBox, % vText

;did work
ControlSend,, {Home}, % "ahk_id " hCtl
return

w:: ;autohotkey help (html help) - get text from list - simple method
;get text from hh_kwd_vlist control via Edit control
ControlGet, hCtl, Hwnd,, Edit1, A
vOutput := ""
;there were 924 items last time I tried
Loop, 2000
{	ControlGetText, vText,, % "ahk_id " hCtl
	vOutput .= vText "`r`n"
	if (vText = "{Blind}")
		break
	SendInput, {Down}
	vText2 := vText
	Loop, 1000
	{
		ControlGetText, vText,, % "ahk_id " hCtl
		if !(vText = vText2)
			break
		Sleep, 10
	}
}
Clipboard := vOutput
MsgBox, % "done"
return

;==================================================

SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
    local MsgReply
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    MsgReply := (ErrorLevel = "FAIL") ? "" : ErrorLevel
    ErrorLevel := (ErrorLevel = "FAIL")
    return MsgReply
}

Code: Select all

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

e:: ;autohotkey help (html help) - get text from list - using Acc
;warning: only gets visible rows
ControlGet, hCtl, Hwnd,, hh_kwd_vlist1, A
vOutput := ""
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
Loop, % oAcc.accChildCount
	try vOutput .= oAcc.accName(A_Index) "`r`n"
vOutput := SubStr(vOutput, 1, -2)
Clipboard := vOutput
MsgBox, % "done"
return

can't thank you more. Really appreciate your work.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, eqv, esp901, Google [Bot], JoeWinograd and 56 guests