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

Get help with using AutoHotkey and its commands and hotkeys
Travis Banger
Posts: 2
Joined: 11 Feb 2017, 15:09

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

11 Feb 2017, 15:44

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 1484 times
Last edited by Travis Banger on 11 Feb 2017, 16:40, edited 6 times in total.
Guest

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

11 Feb 2017, 15:49

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...
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

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

11 Feb 2017, 15:58

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.
Travis Banger
Posts: 2
Joined: 11 Feb 2017, 15:09

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

11 Feb 2017, 16:02

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
User avatar
jeeswg
Posts: 6647
Joined: 19 Dec 2016, 01:58
Location: UK

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

11 Feb 2017, 19:48

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
Last edited by jeeswg on 24 Feb 2017, 16:33, edited 3 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6647
Joined: 19 Dec 2016, 01:58
Location: UK

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

11 Feb 2017, 20:42

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
Last edited by jeeswg on 12 Feb 2017, 08:00, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 6464
Joined: 02 Oct 2013, 08:51
Location: Germany

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

12 Feb 2017, 07:52

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?

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Enlprck, MannyKSoSo, potroveio and 154 guests