random Sleep time

Ask gaming related questions (AHK v1.1 and older)
spania
Posts: 7
Joined: 17 Nov 2019, 08:46

random Sleep time

21 Jan 2020, 19:52

Hello all,

I m trying to put a ramdom delay before to send, instead of the sleep function, without succes.
Can someone help me?

Code: Select all

z::
Loop
{
PixelSearch, Px, Py, 712, 746, 908, 896, 0xB14927, 0, Fast RGB
		if (ErrorLevel=0)
	{
		send, $
		Sleep, 200
	}
PixelSearch, Px, Py, 1114, 865, 1167, 944, 0xA29260, 0, Fast RGB
		if (ErrorLevel=0)
	{
		send, a
		Sleep, 200
	}
}
until !GetKeyState(A_ThisHotkey,"P")	
return
[Mod edit: Replaced quote tags with [code][/code] tags.]
King_Fisher
Posts: 9
Joined: 21 Jan 2020, 01:26

Re: random Sleep time

22 Jan 2020, 04:48

Use search in help docs and look up timer random. That should Be what you are looking for exactly.
User avatar
Chunjee
Posts: 1501
Joined: 18 Apr 2014, 19:05
Contact:

Re: random Sleep time

18 Feb 2020, 18:39

My take:

Code: Select all

; REQUIRES https://biga-ahk.github.io/biga.ahk
A := new biga()

z::
Loop
{
PixelSearch, Px, Py, 712, 746, 908, 896, 0xB14927, 0, Fast RGB
		if (ErrorLevel=0)
	{
		send, $
		sleep, % A.random(150, 200)
	}
PixelSearch, Px, Py, 1114, 865, 1167, 944, 0xA29260, 0, Fast RGB
		if (ErrorLevel=0)
	{
		send, a
		sleep, % A.random(150, 200)
	}
}
until !GetKeyState(A_ThisHotkey,"P")	
return
Can be done in plain ahk with extra variable juggling and Random command
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: random Sleep time

18 Feb 2020, 19:55

Example:

Code: Select all

Sleep, randsleep(100,1000)

randsleep(min,max) {
    Random, num, min, max
    return num
}

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 102 guests