Screen position of items in listview?

Get help with using AutoHotkey and its commands and hotkeys
drizzt
Posts: 27
Joined: 20 Apr 2018, 20:44

Screen position of items in listview?

24 Apr 2018, 21:20

How do i get the screen position of items in a list view so i can click on them?
Also not all items are shown on screen and need to be scrolled up or down to access them. How would I get screen position of those items?
Noesis
Posts: 299
Joined: 26 Apr 2014, 07:57

Re: Screen position of items in listview?

25 Apr 2018, 02:16

Depending on exactly what it is you're trying to do, you possibly don't need the screen position at all. Odds are you can use ControlGet to get the contents of the listview and you could use ControlSend to manipulate the selection.

If you already know what you want selected, since listviews react to keys (i.e. type the first few characters of an entry and the listview will jump to that entry) then you probably don't need ControlGet either. Just send the keys for the name of the entry to the listview, and it should get selected. Far easier to send keys than try to determine the position for a mouse click.

If you really have to use clicks then you're likely better off using controlclick rather than click and setting the Mouse CoordMode to Relative, Window or Client. Screen coordinates are likely the last thing you actually want to use.
Guest

Re: Screen position of items in listview?

25 Apr 2018, 05:04

Use SendMessages to get visible items in a listview, here is a handy list of contstants
https://github.com/AHK-just-me/AHK_Gui_ ... stView.ahk
LVM_FINDITEM or LVM_HITTEST should be able to help you get the first visible item I think.

You can consult the MS website for details on what's what https://msdn.microsoft.com/en-us/librar ... s.85).aspx
(or just google the constants name + sendmessage to find posts either AutoHotkey or other languages providing examples)

If you want to make sure a specific column is visible you can use LV_Modify and "VIS" - https://autohotkey.com/docs/commands/Li ... RowOptions
drizzt
Posts: 27
Joined: 20 Apr 2018, 20:44

Re: Screen position of items in listview?

25 Apr 2018, 19:46

Noesis wrote:Depending on exactly what it is you're trying to do, you possibly don't need the screen position at all. Odds are you can use ControlGet to get the contents of the listview and you could use ControlSend to manipulate the selection.

If you already know what you want selected, since listviews react to keys (i.e. type the first few characters of an entry and the listview will jump to that entry) then you probably don't need ControlGet either. Just send the keys for the name of the entry to the listview, and it should get selected. Far easier to send keys than try to determine the position for a mouse click.

If you really have to use clicks then you're likely better off using controlclick rather than click and setting the Mouse CoordMode to Relative, Window or Client. Screen coordinates are likely the last thing you actually want to use.
Im still not sure how I would be able to drag specific items. For example In 7zip there is a listview of say 100 files. how do i click on a specific file I specify and drag it to my desktop for example
Noesis
Posts: 299
Joined: 26 Apr 2014, 07:57

Re: Screen position of items in listview?

26 Apr 2018, 02:08

Yeah keys wont work for dragging. You'll need the Messages "Guest" mentioned. The link he/she provided for msdn seems broken, but the descriptions can be found here MSDN List View Messages. You'll have to do some research.

The methodology will be something like get the row you need (ContolGet should be able to do that), make it visible (otherwise you can't drag it, guest illustrated that), then use LVM_GetItemRect message to find it's bounding rectangle (do some searches/research on how to implement & use it, one thing about the messages is they use a 0 based index for items). I'm not certain what type of coordinates the message will return, could be client or screen based, but you just need to convert to whatever you use, probably screen, as what I said in my previous post, was assuming the operation would take place entirely within the List View. You then need to implement the drag & do the drop, to wherever you plan to do that.

Another option is you might be able to do a copy & paste instead ? not sure, but might be easier. Also you could possibly do it via command prompt too. Point being drag & drop is easy & intuitive for a user, but not so much to automate in a script.

Anyway, good luck.
drizzt
Posts: 27
Joined: 20 Apr 2018, 20:44

Re: Screen position of items in listview?

26 Apr 2018, 19:31

OK thanks! This is a lot of helpful info that should get me started. Another problem though is that the listview I have is in windows 10 64 bit and the Spyxx_amd64.exe I use to see what the messages are doesnt seem to work in windows 10...gottas solve this problem first!
Noesis
Posts: 299
Joined: 26 Apr 2014, 07:57

Re: Screen position of items in listview?

27 Apr 2018, 01:54

In case you're not aware, with the Spyxx type programs, the version to use depends on the software you are trying to monitor, not the OS, so if you're trying to monitor a 32bit program running on Win 10 64 bit, you should use the 32 bit version of Spyxx. This may be irrelevant, but is a common pitfall.
User avatar
jeeswg
Posts: 5956
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Screen position of items in listview?

01 May 2018, 03:17

Here's some code to list/focus listview items. You'll need the Acc library (see the link).

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:: ;listview control - get item positions + text
;e.g. test on 7-Zip
ControlGet, hCtl, Hwnd,, SysListView321, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
vOutput := ""
Loop, % oAcc.accChildCount
{
	try vAccName := oAcc.accName(A_Index)
	catch
		continue
	oRect := Acc_Location(oAcc, A_Index)
	vAccLocation := Format("X{} Y{} W{} H{}", oRect.x, oRect.y, oRect.w, oRect.h)
	vOutput .= vAccLocation "`t" vAccName "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput
return

w:: ;listview control - select item with specific text and get its position
;e.g. test on 7-Zip
vNeedle := "AutoHotkey.chm"
ControlGet, hCtl, Hwnd,, SysListView321, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
Loop, % oAcc.accChildCount
{
	try vAccName := oAcc.accName(A_Index)
	catch
		continue
	if !(vAccName = vNeedle)
		continue
	oRect := Acc_Location(oAcc, A_Index)
	vAccLocation := Format("X{} Y{} W{} H{}", oRect.x, oRect.y, oRect.w, oRect.h)
	vOutput := vAccLocation "`t" vAccName "`r`n"
	;SELFLAG_TAKESELECTION := 0x2 ;SELFLAG_TAKEFOCUS := 0x1
	oAcc.accSelect(0x3, A_Index)
	break
}
Clipboard := vOutput
MsgBox, % vOutput
return
For 7-Zip you can use F5 to get the Copy dialog for the selected files, instead of using drag-and-drop.

Code: Select all

;Get Info from Context Menu (x64/x32 compatible) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=31971

q:: ;7-Zip - show Copy dialog
PostMessage, 0x111, 231,,, A ;WM_COMMAND := 0x111 ;Copy To...
return
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”

Who is online

Users browsing this forum: Brazolek123, evilC and 104 guests