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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ballistics1142
Posts: 12
Joined: 18 Mar 2017, 07:50

Sent key=Random | Delay between=100-1000

28 Mar 2017, 07:25

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.
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

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

28 Mar 2017, 07:38

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
}
Last edited by TheDewd on 28 Mar 2017, 08:39, edited 1 time in total.
ballistics1142
Posts: 12
Joined: 18 Mar 2017, 07:50

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

28 Mar 2017, 08:18

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)
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

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

28 Mar 2017, 08:32

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 142 guests