Repeating action during Sleep

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MacroMania
Posts: 2
Joined: 26 Jan 2022, 04:53

Repeating action during Sleep

Post by MacroMania » 26 Jan 2022, 05:02

Greetings everyone!

As this is my first post I would just like to say how excited I am to be a part of this community. I've always enjoyed creating macros - who doesn't enjoy making life more efficient!?

I've been learning AHK for about a week now and I must say, all those other GUI macro programs I've used were a total waste of time :lol:

ONTO THE ACTUAL POINT OF THIS POST

I am trying to loop a set of actions while the script is otherwise sleeping / paused.

Code: Select all

Random, rand, 5000,6000
   while Sleep, rand
    {
        MouseGetPos, x, y
        ToolTip, % begin_x ", " begin_y "`n" Abs(begin_x-x) " x " Abs(begin_y-y)
    }
exit
Obviously the above doesn't work, but it gives you a clear idea of what I'm trying to do.

User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Repeating action during Sleep

Post by Smile_ » 26 Jan 2022, 05:31

You want to do certain stuffs while the script is paused? How can we consider it is paused if it is currently doing something?, that doesn't seems to be possible for me.
You might mean something else other than that?

Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Repeating action during Sleep

Post by Rohwedder » 26 Jan 2022, 06:12

Hallo,
while the script is sleeping, it can still be active. Try:

Code: Select all

Random, rand, 5000,6000
MouseGetPos, begin_x, begin_y
SetTimer, Actions, 50
Sleep, rand
SetTimer, Actions, Off
exit
Actions:
MouseGetPos, x, y
ToolTip, % begin_x ", " begin_y "`n" Abs(begin_x-x) " x " Abs(begin_y-y)
Return

MacroMania
Posts: 2
Joined: 26 Jan 2022, 04:53

Re: Repeating action during Sleep

Post by MacroMania » 29 Jan 2022, 06:08

Thank you for the responses everyone.

I'm afraid I answered my own question before my post was even approved... And unfortunately I did not get any email notifying me when the post WAS approved.
I apologize to those who responded for wasting their time :oops:

The solution I found was using a timer to (effectively) pause the script but still continue to search for an image while the timer is running.

Code: Select all

ImageTimer (MinTime, MaxTime, xTop, yTop, xBottom, yBottom, tol, image) {
	Random, rand, MinTime, MaxTime
	start_time := A_TickCount
	time_to_run := rand
	end_time := start_time + time_to_run
		while (A_tickcount < end_time)
		{
		ImageSearch, FoundX, FoundY, xTop, yTop, xBottom, yBottom, *tol image
		if (ErrorLevel = 2) {
		MsgBox Could not conduct the image search.
		else if (ErrorLevel = 1) {
		; image not found
		Found := 0
		}
		else {
		; image found
		Found := 1
		return Found
		break
		}
		}
		}
}

User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Repeating action during Sleep

Post by Smile_ » 29 Jan 2022, 06:36

That is what @Rohwedder suggested.

Post Reply

Return to “Ask for Help (v1)”