How to Loop For Specific Time

Get help with using AutoHotkey and its commands and hotkeys
trevtrev4
Posts: 2
Joined: 19 Apr 2019, 18:44

How to Loop For Specific Time

19 Apr 2019, 18:52

Sorry if this is a stupid question but I am new to this, I can't figure out a way to loop my loop function for a specific amount of time any ideas or help on how to do this would be greatly appreciated.



Here is the code I have

#NoEnv
SendMode Input

~F8::Suspend
~End::ExitApp
~F7::Reload

LCtrl & ~LButton::
Loop

If GetKeyState("LButton", "LCtrl") {
Sleep, 6
mouseXY(3,3)
}
else
break


Return
}



mouseXY(x,y)
{
DllCall("mouse_event",int,1,int,x,int,y,uint,0,uint,0)
}
User avatar
DataLife
Posts: 326
Joined: 29 Sep 2013, 19:52

Re: How to Loop For Specific Time

19 Apr 2019, 22:56

Can you explain somethings...
What does your loop function do?

You have an odd number of curly braces { }. It looks like a opening curly brace is missing.

Which one is missing? Is it the one that should come after Loop ?

How much of your code is in the "loop function" you mentioned?

On your sleep, are you trying to sleep 6ms or 6 seconds? The sleep command uses milliseconds, so 6 seconds would be 6000

Also, to make your code easier to read in the forum use code tags like this... ["code"]Your code goes here["/code"]. I added the quotes so that it would not create a code box on my example. On your post remove the quotes and use the preview button to see what it looks like.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to Loop For Specific Time

19 Apr 2019, 23:19

You could use Loop (until) combined with A_TickCount, like so:

Code: Select all

StartTime := A_TickCount
Loop {
	If GetKeyState("LButton", "LCtrl") {
		Sleep, 6
		mouseXY(3,3)
	}
	else break
} Until A_TickCount - StartTime > 60000	; Loop until 60 seconds have passed
Last edited by Osprey on 20 Apr 2019, 05:18, edited 1 time in total.
swagfag
Posts: 2908
Joined: 11 Jan 2017, 17:59

Re: How to Loop For Specific Time

20 Apr 2019, 03:57

this has a very low chance of breaking out of the loop, u want to use >
Last edited by swagfag on 15 Oct 2019, 10:37, edited 1 time in total.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to Loop For Specific Time

20 Apr 2019, 05:19

swagfag wrote:
20 Apr 2019, 03:57
this have a very low chance of breaking out of the loop, u want to use >
You're right. I was in too much of a rush. I've edited it. Thanks.
rayen
Posts: 3
Joined: 15 Oct 2019, 07:04

Re: How to Loop For Specific Time

15 Oct 2019, 09:15

swagfag wrote:
20 Apr 2019, 03:57
this have a very low chance of breaking out of the loop, u want to use >
yo bro do u have discord i wanna ask you something please
swagfag
Posts: 2908
Joined: 11 Jan 2017, 17:59

Re: How to Loop For Specific Time

15 Oct 2019, 10:38

@rayen just ask here if its got something to do with this topic
otherwise, create a new one and ask there

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Bullex, chngrcn, just me, tmplinshi and 258 guests