ImageWait function ... how it works and how to call?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

ImageWait function ... how it works and how to call?

12 Feb 2018, 05:12

Hi guys, I would like to edit my script containing imagesearch in a loop with the imagewait function.

I know that the user "JSLover" wrote years ago the ImageWait function but I find very little documentation and I do not know how to recall it in my script since it is not included in ahk.
The various links that refer to the function on base.ahi do not seem to be working anymore.

Can someone give me a hand about it?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 07:06

Please post the function. It should be easy to figure out.
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 09:23

boiler wrote:Please post the function. It should be easy to figure out.
The function was posted here, but the link does not seem to be reachable anymore:

https://autohotkey.com/board/topic/14591-pixelcolorwait

the only other material I found is the following but in no thread is there the function file:
https://autohotkey.com/board/topic/5010 ... -be-found/
https://autohotkey.com/board/topic/8787 ... lp-needed/
https://autohotkey.com/board/topic/7805 ... -searchgt/

No other mention, yet it seemed to work perfectly.
Thank you so much
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 09:38

So you don't have a copy of it? Then it looks like you're out of luck. Fortunately, it's a pretty easy function to recreate the equivalent functionality. One of the parameters would be the file path to the image file, and optionally you would have parameters for a rectangle to search within if you don't want to limit the search instead of the entire screen (and possibly whether you want it to search relative to a window instead of the screen). Then in the function you would loop until ErrorLevel is 0, and inside the loop would be the ImageSearch command.
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 11:06

I never worked with image search so please take it with the grain of salt.
Based on what i could gather from the links provided by teosc's and as boiler kindly suggested, i guess it would look something like this?

This is my first try at recreating it:

Code: Select all

; ImageWait( found X, found Y, rectangle x to start search from, rectangle y to start search from, rectangle x to end search from, rectangle y to end search from, image file, wait X amount in MS before ending the wait and aborting the search, interval in MS to repeat search, coord mode - Screen|Relative|Window|Client  )
; Remarks
;	If "p_waitms", it will run infinitely.
;	If "p_checkinterval" is 2000 and "p_waitms" is 1500, it will do only one search then abort. Play around with those values. Curious how JSLover make the function.
;	If "p_checkinterval" is 1500 and "p_waitms" is 2000, it will do one more search then abort. Play around with those values.
; Im curious how JSLover make the function.

ImageWait(ByRef p_x="", ByRef p_y="", p_x1="", p_y1="", p_x2="", p_y2="", p_img="", p_waitms=0, p_checkinterval="", p_coordmode="Screen") {
	CoordMode, Pixel, %p_coordmode%
	result : = 0
	timeout := 0

	Loop
	{
		ImageSearch, p_x, p_y, p_x1, p_y1, p_x2, p_y2, %p_img%
		if ErrorLevel = 0
		{
			result := 1
			break
		}
		
		if (p_checkinterval = "" or p_checkinterval = 0)
			timeout += 1
		else
		{
			timeout += p_checkinterval
			Sleep %p_checkinterval%
		}
		if (timeout != 0 and timeout >= p_waitms)
			break
	}
	return result
}
Again, never worked with such things so i dont really know if the function even remotly looked like this but i hope this could work and jump-start this topic. xD
If there are some mistakes, please someone post a fixed version? Good luck! :)
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 12:55

Looks like it should work, but I don't see the purpose or benefit of having the default value of "" (empty string) for the first 7 parameters. It doesn't make sense for the first 2 parameters, and the ImageSearch will fail if any of the next 5 are blank. You should just remove the ="" from the first 7 parameters.
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 13:32

No idea. xD
I just tried to recreate it from the posts and among them was this from a guest i believe was JSLover
Last post in: https://autohotkey.com/board/topic/5010 ... -be-found/
JSLover wrote: I believe in 2007, the last time I edited that function ByRef params could not be optional, but I will completely do that in the next update...until then you can edit your copy...

From...

Code: Select all

ImageWait(ByRef p_x, ByRef p_y, p_x1, p_y1, p_x2, p_y2, p_img, p_waitms=0, p_checkinterval="") {
To...

Code: Select all

ImageWait(ByRef p_x="", ByRef p_y="", p_x1="", p_y1="", p_x2="", p_y2="", p_img="", p_waitms=0, p_checkinterval="") {
...that makes all params optional, cuz I don't think p_x1, p_y1, p_x2, p_y2 & p_img can be in the middle & not be optional. The current param order is to mimic ImageSearch...should I move the params around?...putting the output params after p_img...or at the end? I was really assuming everyone would want/need to know where an image was found, not just wait for it to be found...perhaps I should rename ImageWait() to ImageWaitGetPos() & make ImageWait() not have the output params?...
Since he wanted to update it to this, i guess he had a reason? But this is more of a template i guess that can be further modified to whatever needs there are.
Like, i added CoordMode param at the end as well. I guess the p_x1="" could be changed to p_x1=0 and p_x2="" to p_x2=A_ScreenWidth. At least thats what i would do if i was using the function. xD
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 13:44

Now with imagesearch in a loop, despite the inclusion of a sleep, I have a cpu commitment of 3-4%.

According to you with the approach of imagewait the consumption of resources improves?
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: ImageWait function ... how it works and how to call?

12 Feb 2018, 14:07

teosc wrote:Now with imagesearch in a loop, despite the inclusion of a sleep, I have a cpu commitment of 3-4%.

According to you with the approach of imagewait the consumption of resources improves?
Nobody has made such claims so there is no according to anyone.

But since you mentioned it, yes. A higher interval should be less taxing since you dont call imagesearch that often but as I believe imageSearch is a taxing operation so there will be some more than usual cpu/ram committed.
And the interval is usually set by what is being scanned.
If its some game that shows something briefly, you would need less intervals between scans while some program / windows that would show something that is going to stay on screen for a while or until interacted with, you can set it much higher. From 1000 ms to 10000 ms and more.
Guest

Re: ImageWait function ... how it works & how to call?

19 Sep 2018, 18:19

teosc wrote:I know that the user "JSLover" wrote years ago the ImageWait function...

The various links that refer to the function on base.ahi do not seem to be working anymore.
...it sucks that all the links broke...however, since then, I've finally secured my own domain, so perhaps they won't break in the future...
teosc wrote:The function was posted here, but the link does not seem to be reachable anymore:

https://autohotkey.com/board/topic/14591-pixelcolorwait
...that particular URL (in the thread u linked to)...
  • https://ahknet.autohotkey.com/JSLover/Scripts/Includes/Base.ahi
...is not where Base.ahi (or ImageWait or PixelWait) ever was. That URL is the result of the AutoHotkey admins doing a search & replace to remove all old links to AutoHotkey.net, which I agree they needed to do (some moron owns AutoHotkey.net now), but they should have put up a msg on those URLs (with a 503 or 404 status code) explaining the situation (right now it's coming up as NXDOMAIN, which means ahknet.AutoHotkey.com doesn't even have an A record, which means it's not in the DNS at all)
boiler wrote:So you don't have a copy of it? Then it looks like you're out of luck.
...nope, he's not out of luck, since he mentioned JSLover (& the rest of the page mentions AutoHotkey), I randomly found this thread!...every once in a while I Google for: "JSLover" "AutoHotkey" to find my mentions...& I found this!...a few months late, but I'm here!

To contact JSLover...
  • Unfortunately, I have not signed up to this "new" forum yet, I had an account on the old forum, but accounts were not imported, so I can't be contacted here yet.

    I also have not created a Contact/Feedback form on my domain yet (I started writing one, but haven't gotten back to it).

    So, I think the best way to (eventually) get my attention is something I'm gonna create/suggest right now: post on this forum (or possibly anywhere online) & include the string "JSLoverFeedback" (no space & cased like that...u don't need the double quotes when posting it, but I will be Googling it with double quotes for an exact match).
Anyway, as for the actual topic, I'm gonna post new links/URLs below, but I want people searching for the old URLs to be able to find something, so here are all the old URLs I can think of right now...

Old URLs...
  • http://r.secsrv.net/AutoHotkey/Scripts/Includes/Base.ahi

    http://AutoHotkey.net/JSLover/Scripts/Includes/Base.ahi

    http://AutoHotkey.net/~JSLover/Scripts/Includes/Base.ahi

    https://ahknet.autohotkey.com/JSLover/Scripts/Includes/Base.ahi
New links / URLs...
  • Base.ahi
    https://JSLover.net/AutoHotkey/Scripts/Includes/Base.ahi

    ImageWait()
    https://JSLover.net/AutoHotkey/Functions/ImageWait

    PixelWait()
    https://JSLover.net/AutoHotkey/Functions/PixelWait

    (Note: These new URLs might have an error msg until I set them up...don't panic!...keep checking & they should work soon™...or at least "eventually". These should be final (they should not break, I fully control them), cuz even if I move stuff around, I can redirect them anywhere I need to...all previous URLs I didn't have full control over)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 242 guests