Page 1 of 1

My first project: How hard/easy it is to develop a script for this?

Posted: 11 Feb 2017, 15:44
by Travis Banger
Hello folks! I was pleasantly surprised to discover this great tool and its community. As a contributor of source code to OSS projects myself, I feel at home.

I hope I am not being too ambitious, my first project should behave as follows (BTW, the front end was developed by myself, and thus it is subject to any necessary modifications in order to make it more amenable to AutoHotkey; however, there is a 2nd. backend GUI which is 3rd. party. It starts when any *.pol file is double-clicked):

There is a grid of -say- 100 rows (variable in each run) by 3 columns (fixed). Initially the first column is filled (always), and the objective of the AHK script is to fill columns 2 and 3. They are PDF files, generated by clicks inside the 3rd. party app. The script should "visually" scan the grid (columns 2 and 3) and every time it finds a red "X", it double clicks on the same row, column 1. Windows executes the 3rd. party app, inside it the clicks generate the missing file and immediately (I use real-time folder watch) the red X becomes a green check mark. The red X denotes a file that does not exist yet.

Eventually, at the end of the scan, all grid cells contain a green check mark. In the case in the image below the script should generate all the files in column 2, plus 5 files in column 3.

I guess I should be able to detect the rectangular regions where the {X or Check Mark} icons are located. My doubt is about scrolling, since the 100 or more rows do not fit the screen.

Well, I guess this is enough info. See screenshot of the application written by myself in the attachment.

TIA,

Travis
To Be Automated.png
To Be Automated.png (96.38 KiB) Viewed 3878 times

Re: My first project: How hard/easy is to develop a script for this?

Posted: 11 Feb 2017, 15:49
by Guest
What information does the Window Spy reveal when you click on the "three columns" (looks like a listview).
Right click ahk tray icon, window spy and hover your mouse over the control - if you can read it in AHK that will give you a good starting point, if not...

Re: My first project: How hard/easy is to develop a script for this?

Posted: 11 Feb 2017, 15:58
by Exaskryz
This shouldn't be too tough actually. Here's what I'm thinking.

Use ImageSearch to search for the X icon. It will give you back coordinates for the top-left corner of the icon. Use the Y value, add just a little bit to it (in AHK, larger Y values mean lower on the screen), and a set X value (that's always in Column 1) to use the Click command to do your double click on column 1.

Because you say the red X should in real time change to a green checkmark, it should be a matter of just repeating your ImageSearch over and over until it doesn't find any red X's. At that point, do a scroll down (Send {PgDn} or click on the scroll bar arrow a few times to reliably scroll down a set distance.)

You can add in a check to see if the scrollbar is at the bottom by capturing an Image of the bottom it of the scrollbar being vertically adjacent to that scroll-down arrow button in the scrollbar, and doing an ImageSearch for that. If it were found, then you don't need to do any further checks.

Re: My first project: How hard/easy it is to develop a script for this?

Posted: 11 Feb 2017, 16:02
by Travis Banger
Exaskryz:

All I can say is WOW! I wish I had discovered this resource years ago. Blame it on my GUI-less Unix server background. :)

-Travis

Re: My first project: How hard/easy it is to develop a script for this?

Posted: 11 Feb 2017, 19:48
by jeeswg
To click an image every time it appears on the screen,
do ImageSearch on the entire window area.

The next search area should be as follows:
the height of the needle image, in a thin strip
starting one pixel right of the left of the current found image,
all the way to the right edge of the window area.
Click all the images in that strip.

The next search area should as wide as the entire window area,
but the top of the region should be
one pixel below the top of the current found image.

[EDIT:]
Btw scrolling usually occurs in pixel intervals,
so hopefully that would not pose a problem.

I found the script I used for this:
Note: the needle image was a red square size 24x24.
I copied and pasted multiple squares into MS Paint, set at 100% zoom.

Code: Select all

q:: ;jump to next instance of image on screen
vPath = %A_Desktop%\redsquare.png
vPosW := 24, vPosH := 24

CoordMode, Pixel, Screen
CoordMode, Mouse, Screen

vPosX1 := 0, vPosY1 := 0
vPosX2 := A_ScreenWidth, vPosY2 := A_ScreenHeight

vCheckingStrip := 0
Loop
{
ImageSearch, vPosX, vPosY, vPosX1, vPosY1, vPosX2, vPosY2, *Trans00FF00 %vPath%
vImageFound := !ErrorLevel ;0/1/2 found/not found/problem
if !vCheckingStrip && !vImageFound
	break
if vCheckingStrip && !vImageFound
	vPosX1 := 0, vPosY1 := vPosYg+1, vPosX2 := A_ScreenWidth, vPosY2 := A_ScreenHeight, vCheckingStrip := 0

if vImageFound
{
	vPosXg := vPosX, vPosYg := vPosY
	vCheckingStrip := 1 ;this variable means we are checking the rest of the strip to the right of a found image
	MouseMove, %vPosX%, %vPosY%, 0
	vPosX1 := vPosX+1, vPosY1 := vPosY, vPosX2 := A_ScreenWidth, vPosY2 := vPosY + vPosH

	if (vPosY + vPosW > A_ScreenWidth)
		vPosX1 := 0, vPosY1 := vPosY+1, vPosX2 := A_ScreenWidth, vPosY2 := A_ScreenHeight, vCheckingStrip := 0
	Sleep 500
}
}
MsgBox % "done"
Return
Version that searches for a pixel colour rather than an image:
after 4 hours i decided i should get help lol - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28516

Re: My first project: How hard/easy it is to develop a script for this?

Posted: 11 Feb 2017, 20:42
by jeeswg
It may be that you can do this directly.
If you try AccViewer it may be that the buttons have checked/unchecked status,
then you could use a loop and 'click' on the appropriate buttons,
by using accDoDefaultAction.

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

Re: My first project: How hard/easy it is to develop a script for this?

Posted: 12 Feb 2017, 07:52
by just me
Well, I guess this is enough info. See screenshot of the application written by myself in the attachment.
Do you use a 'common' SysListView32 control?