Page 1 of 1

Sent key=Random | Delay between=100-1000

Posted: 28 Mar 2017, 07:25
by ballistics1142
Hi,

Fairly new to AHK scripting. I recieved help earlier in the month regarding another script. I am however looking at adjusting it for a better use in my enviroment.

Here's is what I had help with before;

Code: Select all

Loop ;endless
{
	EndTaskATime := A_Tickcount + 15*60*1000 ;15 mins
	Loop
	{
		Send, 1
		Sleep 1000
		Send, 2
		Sleep 1000
		Send, 3
		Sleep 1000
	}
	Until, (A_Tickcount > EndTaskATime)
	Send, 4
	Sleep 1000
	Send, 5
	Sleep 1000
	Send, 6
	Sleep 1000
}
What I am after is to have the keys that are "sent" to be "random" and the "sleep" to be delayed between two values such as 100-1000.

Re: Sent key=Random | Delay between=100-1000

Posted: 28 Mar 2017, 07:38
by TheDewd
This might not be what you requested... Hope it helps anyway.

Code: Select all

Loop {
    EndTime := A_TickCount + 900000 ; 15 Minutes

    Loop {
        Send, % RandomChr()
        Sleep, % RandomNum(100, 1000)
        Send, % RandomChr()
        Sleep, % RandomNum(100, 1000)        
        Send, % RandomChr()
        Sleep, % RandomNum(100, 1000)        
        IfGreater, A_TickCount, % EndTime, Break
    }
    
    Send, % RandomChr()
    Sleep, % RandomNum(100, 1000)
    Send, % RandomChr()
    Sleep, % RandomNum(100, 1000)    
    Send, % RandomChr()
    Sleep, % RandomNum(100, 1000)    
}

RandomChr(Min := 65, Max := 90) { ; A=65, Z=90
    Random, RandChr, % Min, % Max
    return Chr(RandChr)
}

RandomNum(Min, Max) {
    Random, RandNum, % Min, % Max
    return RandNum
}

Re: Sent key=Random | Delay between=100-1000

Posted: 28 Mar 2017, 08:18
by ballistics1142
TheDewd wrote:This might not be what you requested... Hope it helps anyway.

Code: Select all

Loop {
    EndTime := A_TickCount + 900000 ; 15 Minutes

    Loop {
        Send, % RandomChr()
        Sleep, % RandomNum(100, 1000)
        Send, % RandomChr()
        Sleep, % RandomNum(100, 1000)        
        Send, % RandomChr()
        Sleep, % RandomNum(100, 1000)        
        IfGreater, A_TickCount, % EndTime, Break
    }
    
    Send, % RandomChr()
    Sleep, % RandomNum(100, 1000)
    Send, % RandomChr()
    Sleep, % RandomNum(100, 1000)    
    Send, % RandomChr()
    Sleep, % RandomNum(100, 1000)    
}

RandomChr(Min := 64, Max := 90) {
    Random, RandChr, % Min, % Max
    return Chr(RandChr)
}

RandomNum(Min, Max) {
    Random, RandNum, % Min, % Max
    return RandNum
}

First off thanks for the prompt reply, all help is greatly appreciated!
So with this bit

Code: Select all

RandomChr(Min := 64, Max := 90)
I am guessing this represents what characters are to be sent. Now would it be possible to have the randomchar to select from characters in an array? Randomchar(a,b,c,d,e,f,g,h,i)

Re: Sent key=Random | Delay between=100-1000  Topic is solved

Posted: 28 Mar 2017, 08:32
by TheDewd
ballistics1142 wrote:So with this bit

Code: Select all

RandomChr(Min := 64, Max := 90)
I am guessing this represents what characters are to be sent. Now would it be possible to have the randomchar to select from characters in an array? Randomchar(a,b,c,d,e,f,g,h,i)
Yes, however the Min value should have been 65. A=65, Z=90

See the code below on using an Array of characters:

Code: Select all

#SingleInstance, Force

ChrArray := ["A","B","C","D","E","F","G","H","I","J","K"]

Loop {
    EndTime := A_TickCount + 900000 ; 15 Minutes

    Loop {
        Send, % RandomChrArray(ChrArray)
        Sleep, % RandomNum(100, 1000)
        Send, % RandomChrArray(ChrArray)
        Sleep, % RandomNum(100, 1000)
        Send, % RandomChrArray(ChrArray)
        Sleep, % RandomNum(100, 1000)
        IfGreater, A_TickCount, % EndTime, Break
    }

    Send, % RandomChrArray(ChrArray)
    Sleep, % RandomNum(100, 1000)
    Send, % RandomChrArray(ChrArray)
    Sleep, % RandomNum(100, 1000)
    Send, % RandomChrArray(ChrArray)
    Sleep, % RandomNum(100, 1000)
}

RandomChrArray(ArrayVar) {
    Random, RandChr, 1, % ArrayVar.MaxIndex()
    return ArrayVar[RandChr]
}

/*
RandomChr(Min := 65, Max := 90) { ; A=65, Z=90
    Random, RandChr, % Min, % Max
    return Chr(RandChr)
}
*/

RandomNum(Min, Max) {
    Random, RandNum, % Min, % Max
    return RandNum
}
EDIT: Made some corrections