Newbie in need of help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WillowWhisp
Posts: 2
Joined: 23 Aug 2017, 16:17

Newbie in need of help

23 Aug 2017, 17:18

So, I've never used a macro before, nor have I written a script. I tried Jitbit, which was easy enough to use, but there was just one feature I needed that it didn't have. I've since tried Pulover's Macro Creator and AutoHotKey, but I'm having a hard time figuring out how to use them. I recorded a macro with Pulover's, but when I went to edit the recording, I can't find a way to tell it to click on a random coordinate from within a box/range.

This is the macro I'm trying to make:

Left click down at a random coordinate within a box {(400,100) (500,100) (400,200) (500,200)}
Random milliseconds delay (100-125 milliseconds)
Left click up
Random milliseconds delay (300-400 milliseconds)
Right click down at a random coordinate within a box {(800,100) (900,100) (800,200)(900,200)}
Holding down the right click, drag, taking a randomly selected amount of time between 700-900 milliseconds to complete
Right click up at a random coordinate within a box {(1100,-100)(1200,-100)(1100,-200)(1200,-200)}
Random delay (10-25 seconds)
Repeat


I've looked through the manual and, I'll admit, I'm getting more confused the more I read. :wtf: For one, I'm not sure if Pulover's or AutoHotKey is what I need to use. Second, the only thing I might have figured out is that I need to use Click (x1,y1,x2,y2) with Random,x,%x1%,%x2% and Random,y,%y1%,%y2% (got it from this post) to get randomized clicks within a box, but I've got no clue how to use the Random command for time delays or if the Click (x1,y1,x2,y2) function will work if I change it to Right (x1,y1,x2,y2) or MouseClickDrag (x1,y1,x2,y2) to get the Right click up/down and drag I'm trying to include.

Any help anyone can give is much appreciated! :D
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Newbie in need of help

23 Aug 2017, 19:57

It may not be completely correct but try this.

Code: Select all

loop {
	RngClick("down", 400, 500, 100, 200)
	RngDelay(100, 125)
	Click up

	RngDelay(300, 400)
	RngClick("right down", 800, 900, 100, 200)

	MouseMove, % Rng(1100, 1200), % Rng(-100, -200), % Rng(80, 100)
	Click, Right up
	RngDelay(10000, 25000)
}

RngClick(option, x1, x2, y1, y2) {
	Click, % option " " Rng(x1, x2) " " Rng(y1, y2)
}

RngDelay(min, max) {
	Sleep, % Rng(min, max)
}

Rng(min, max) {
	Random, x, % min, % max
	return x
}
Please excuse my spelling I am dyslexic.
WillowWhisp
Posts: 2
Joined: 23 Aug 2017, 16:17

Re: Newbie in need of help

24 Aug 2017, 17:25

Thank you! From what I can tell it works, I just need to tweak the coordinates and delays. One thing I'd like to add is a hotkey to start and stop the script. I've tried adding Toggle with F5 as the hotkey and it seems to work starting the script, but not stopping it. Is there something I'm missing?

Code: Select all

#MaxThreadsPerHotkey 2

F5::
 {
   Toggle:=!Toggle

   While, Toggle
    {
	RngClick("down", 400, 500, 100, 200)
	RngDelay(100, 125)
	Click up

	RngDelay(300, 400)
	RngClick("right down", 800, 900, 100, 200)

	MouseMove, % Rng(1100, 1200), % Rng(-100, -200), % Rng(80, 100)
	Click, Right up
	RngDelay(10000, 25000)
}

RngClick(option, x1, x2, y1, y2) {
	Click, % option " " Rng(x1, x2) " " Rng(y1, y2)
}

RngDelay(min, max) {
	Sleep, % Rng(min, max)
}

Rng(min, max) {
	Random, x, % min, % max
	return x
    }
}
Return
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Newbie in need of help

24 Aug 2017, 21:34

Well let's try to figure out what happens:
You press F5 first time: first thread runs, toggle is true, the while loop runs and sleeps at the end of the loop.
You press F5 second time: the second thread runs, toggle is false the loop doesn't run and the thread exits.
Know if at this point you will wait until the first thread finishes to sleep and exits everything will be fine, but! If you press F5 third time before the first thread exits the following will happen:
Second thread runs, toggle is true and it enters the while loop, you have now reached your #MaxThreadsPerHotkey 2 and pressing F5 againg will do nothing, the second thread will continue to run forever(well, or until you stop your script) and the first thread will continue to wait for the second to finish.

The following will fix the behavior I described above and will make sure only one thread is ever in the loop, I also formatted your code, function definitions don't belong inside hotkeys, it's correct syntax but looks bad.

Code: Select all

#MaxThreadsPerHotkey 2

F5::
	Toggle := !Toggle
	if (running)
		return
	running := true
	
	While, Toggle
	{
		RngClick("down", 400, 500, 100, 200)
		RngDelay(100, 125)
		Click up

		RngDelay(300, 400)
		RngClick("right down", 800, 900, 100, 200)

		MouseMove, % Rng(1100, 1200), % Rng(-100, -200), % Rng(80, 100)
		Click, Right up
		RngDelay(10000, 25000)
	}
	
	running := false
Return

RngClick(option, x1, x2, y1, y2) {
	Click, % option " " Rng(x1, x2) " " Rng(y1, y2)
}

RngDelay(min, max) {
	Sleep, % Rng(min, max)
}

Rng(min, max) {
	Random, x, % min, % max
	return x
}
You should consider using SetTimer it's much more clear what it does, easier to use and can prevent similar mistakes.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 315 guests