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?
ImageWait function ... how it works and how to call?
Re: ImageWait function ... how it works and how to call?
Please post the function. It should be easy to figure out.
Re: ImageWait function ... how it works and how to call?
The function was posted here, but the link does not seem to be reachable anymore:boiler wrote:Please post the function. It should be easy to figure out.
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
Re: ImageWait function ... how it works and how to call?
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.
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: ImageWait function ... how it works and how to call?
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:
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!
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
}
If there are some mistakes, please someone post a fixed version? Good luck!
Re: ImageWait function ... how it works and how to call?
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.
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: ImageWait function ... how it works and how to call?
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/
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
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/
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.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...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?...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="") {
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
Re: ImageWait function ... how it works and how to call?
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?
According to you with the approach of imagewait the consumption of resources improves?
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: ImageWait function ... how it works and how to call?
Nobody has made such claims so there is no according to anyone.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?
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.
Re: ImageWait function ... how it works & how to call?
...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: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.
...that particular URL (in the thread u linked to)...teosc wrote:The function was posted here, but the link does not seem to be reachable anymore:
https://autohotkey.com/board/topic/14591-pixelcolorwait
- https://ahknet.autohotkey.com/JSLover/Scripts/Includes/Base.ahi
...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!boiler wrote:So you don't have a copy of it? Then it looks like you're out of luck.
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).
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
- 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)
Who is online
Users browsing this forum: Lamron750 and 242 guests