News:

Welcome to our NEW forum! We invite you to sign up today
so it can grow to be a valuable resource to all Toolbox users!

Main Menu

Auto-clicker

Started by oblivion, March 30, 2026, 04:41:57 AM

Previous topic - Next topic

oblivion

Less than serious, I suppose... but I've recently got slightly addicted to a silly game called Cookie Clicker. And I made this, to automate clicking on the cookie to bake more cookies. (Look, I SAID it was silly.)

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Action: Comment "This macro was targeted for: Cookie Clicker"
0002 Action: Comment "You can edit the 'Window: Assign' step to change the target."
0003 Window: Assign "Cookie Clicker.exe"
0004 ;Window: Resize to "1696,1089"
0005 Macro: For assigned window only "1"
0006 Window: Activate for use ""
0007 Macro: Typing speed "def"
0008 Action: Comment "You can right-click the next step to change the macro speed."
0009 Alert: Ask for a line of text "How many clicks?"
0010 Action: Repeat this block "alert$"
0011  Macro: Type keys or use mouse "{@370,600}{leftclick}{z25}"
0012 Action: End of block ""
(End)


Generally, it works pretty well. But if I set it off to do -- say -- 500,000 clicks while I go off and do something else, if I interrupt it (by pressing Esc) it generally stops and restarts, then after a more energetic Esc (by leaning on the key for a couple of seconds) it stops OK but, after a few seconds, so does Toolbox.

For clicks up to a few thousand, it's fine, so I'm wondering if there's a counter somewhere that's objecting to the size of the loop?

Paul (Lead Developer)

Hi Oblivion,

I tested the following action at https://cpstest.org/10-seconds.php to see if all clicks were being registered, and they were. Just make sure your mouse is over the click area before pressing the hotkey to start it. It should report that all 500 were successfully clicked. The reason I mention this is because some apps or websites might not be able to respond to each and every click if they're too fast.

As for your game issue with the Esc key, it sounds like your single keypress of Esc is coincidentally happening during your "{z25}" delay, so the action misses the press and doesn't abort the action at that moment. That's why holding it down works, because the 25 ms timeout ends while you're still holding down the Esc key.

If Toolbox's window is also closing, that would be because pressing the Esc key on it will hide it (until you use its main hotkey to show it again). So make sure it's closed when running the action to avoid that.

Lastly, the limit of repeated loops is 2147483647 (a "long" in computer terms), or you can specify "forever" to repeat indefinitely.

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Action: Repeat this block "500"
0002   Macro: Type keys or use mouse "{leftclick}"
0003 Action: End of block ""
(End)


oblivion

Thanks for looking, Paul.

The script is fine up to about 15000 clicks -- haven't tested it incrementally beyond that. The problems only occurred with loops of half a million and beyond but I think what I might do is put in a condition to click indefinitely if the number input is >99,999 -- see what happens then. If the issue is "too many loops" it'll happen again, and if it's "counting down from half a million" then it won't. :)

Mouse positioning isn't an issue as I'm handling that within the script anyway.

oblivion

#3
Oh. Well, that was a quick experiment.

The updated code is:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Action: Comment "This macro was targeted for: Cookie Clicker"
0002 Action: Comment "You can edit the 'Window: Assign' step to change the target."
0003 Window: Assign "Cookie Clicker.exe"
0004 Macro: For assigned window only "1"
0005 Window: Activate for use ""
0006 Macro: Typing speed "def"
0007 Alert: Ask for a line of text "How many clicks?"
0008 String: Assign "alert$"
0009 Action: Do next step if "string$>99999"
0010   String: Assign "forever"
0011 Action: Repeat this block "string$"
0012   Action: Comment "Next line is for external monitor, line after for internal"
0013   Macro: Type keys or use mouse "{@370,600}{leftclick}{z25}"
0014   ;Macro: Type keys or use mouse "{@300,450}{leftclick}{z25}"
0015 Action: End of block ""
(End)

So it works, as far as it goes. Asking for 1000 clicks in line 7 delivers 1000 clicks then ends. Asking for 5000 clicks in line 7 and then interrupting (with Esc) after a thousand or two aborts processing as expected.

Asking for 5000000 clicks should set the block repeat instruction in line 11 to "forever" -- and apparently does. However, while it clicks away cheerfully at the assigned location indefinitely, an interruption (which is now a requirement!) needs to be made twice and then Toolbox terminates. Toolbox is running as admin (it can't see the target program if not, for some reason) and minimised.

The block that's being executed doesn't change, just the loop parameters do. And it's not about the number of times you go round the loop, I don't think, because it neither crashes nor fails to complete 5000, but DOES crash if it's been round the loop with the "forever" parameter fewer than 5000 times and is then terminated with Esc.

Paul (Lead Developer)

Have you got another free app that you (and I) can test it with? I don't want to buy Cookie Cutter on Steam just to look deeper into it.

When you say Toolbox terminates, do you mean it literally crashes or quits so that it's no longer running?

oblivion

I think you can test it with anything. Open notepad fullscreen and let it rip.

As far as I can tell, it's utterly reliable as long as you're not triggering the forever parameter on the block that starts on line 11. Only one Esc required to terminate it. If it's running indefinitely (or, previously, with a very large number for the loop) then a single Esc causes a hiccup and a continue, then Esc needs to be leaned on, then Toolbox (quietly) crashes. No errors, nothing like that, it just goes away.

For what it's worth, I've reworked it slightly so I don't have to remember which coordinates I want the mouse to click at. The action now looks like this:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Action: Comment "This macro was targeted for: Cookie Clicker"
0002 Action: Comment "You can edit the 'Window: Assign' step to change the target."
0003 Window: Assign "Cookie Clicker.exe"
0004 Macro: For assigned window only "1"
0005 Window: Activate for use ""
0006 Macro: Typing speed "def"
0007 Alert: Ask for a choice "Where is Cookie Clicker?~External monitor~Laptop screen~"
0008 Action: Do this block if "alert$=External monitor"
0009   Alert: Ask for a line of text "How many clicks?"
0010   String: Assign "alert$"
0011   Action: Do next step if "string$>99999"
0012   String: Assign "forever"
0013   Action: Repeat this block "string$"
0014   Macro: Type keys or use mouse "{@370,600}{leftclick}{z25}"
0015   Action: End of block ""
0016 Action: End of block ""
0017 Action: Do this block if "alert$=Laptop screen"
0018   Alert: Ask for a line of text "How many clicks?"
0019   String: Assign "alert$"
0020   Action: Do next step if "string$>99999"
0021   String: Assign "forever"
0022   Action: Repeat this block "string$"
0023   Macro: Type keys or use mouse "{@300,450}{leftclick}{z25}"
0024   Action: End of block ""
(End)

However, I think you could test just by opening notepad fullscreen and running a script that just consisted of lines 21-24 then aborting it with Esc after 20 seconds or so.

I've just tried it.

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 String: Assign "forever"
0002 Action: Repeat this block "string$"
0003   Macro: Type keys or use mouse "{@300,450}{leftclick}{z25}"
0004 Action: End of block ""
(End)

You won't see much happening, apart from the flickering of the Toolbox icon in the notification area, but you should see exactly what I mean when you try to stop the loop.

Paul (Lead Developer)

Okay, I can see what you mean now, from your last snippet. Here's what's happening: The Esc key is correctly aborting the macro in step 3, as expected. But then you're restarting the same aborted macro again immediately... and forever. ;) So you need to manually check for the Esc key being held down in the block (step 4 below), and then abort the repeating block as well. Like this:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 String: Assign "forever"
0002 Action: Repeat this block "string$"
0003  Macro: Type keys or use mouse "{leftclick}{z25}"
0004  Action: Do next step if "{esc}=0"
0005  Action: End of block ""
(End)

Having said this, the action shouldn't crash Toolbox when done your original way, so I need to look into that. :)

oblivion

OK, that seems to fix it. Still don't really understand why the "forever" loop behaves differently to the finite version but a fix is a fix :)

oblivion

I've rewritten the code to simplify things a bit. Well, quite a lot. It's now just a forever loop.

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Action: Comment "This macro was targeted for: Cookie Clicker"
0002 Action: Comment "You can edit the 'Window: Assign' step to change the target."
0003 Window: Assign "Cookie Clicker.exe"
0004 Macro: For assigned window only "1"
0005 Window: Activate for use ""
0006 Macro: Typing speed "def"
0007 Alert: Ask for a choice "Where is Cookie Clicker?~External monitor~Laptop screen~"
0008 Action: Do next step if "alert$=blank$"
0009   Action: Finish ""
0010 Action: Repeat this block "forever"
0011   Action: Do next step if "alert$=External monitor"
0012   Macro: Type keys or use mouse "{@370,600}{leftclick}{z25}"
0013   Action: Do next step if "alert$=Laptop screen"
0014   Macro: Type keys or use mouse "{@300,450}{leftclick}{z25}"
0015   Action: Do next step if "{esc}=1"
0016   Action: Finish ""
0017 Action: End of block ""
0018 Action: Finish ""
(End)

I thought about posting this in the Tips area but I remain determined that 15 and 16 shouldn't be necessary (and don't need to be present if the loop's set to repeat for, say, 10000 steps), and that the coding's very specific to a two-monitor setup where the monitors have different characteristics, so it's barely even a template...

And I only mention it at all because my first go at this routine set string$ to the appropriate coordinates then tried to click {@string$} and it didn't work. So maybe that's a request? ;)

Paul (Lead Developer)

Quote from: oblivion on April 02, 2026, 11:27:46 PMI remain determined that 15 and 16 shouldn't be necessary
I think you're misunderstanding how Esc works with "Macro: Type keys or use mouse". Pressing it does indeed abort the macro, but you're then restarting the macro again (because it's in a loop), so the old escaped macro has correctly stopped but a new one has started instead. It's like whack-a-mole. That's why an extra check for Esc is needed (step 15) to abort the loop itself, instead of just aborting the macro. Steps 15 and 16 are need to make it like pulling out the plug on a whack-a-mole machine so no more moles can pop up after you whack one (Esc on the macro).

Quote from: oblivion on April 02, 2026, 11:27:46 PMtried to click {@string$} and it didn't work

This works here as expected:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 String: Assign "123,456"
0002 Macro: Type keys or use mouse "{@string$}{leftclick}{z25}"
(End)

oblivion

Hi Paul,

Try this. Notepad fullscreen, Toolbox minimised. The test from previously, with a single modification, then try to abort it with Esc.

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 String: Assign "10000"
0002 Action: Repeat this block "string$"
0003  Macro: Type keys or use mouse "{@300,450}{leftclick}{z25}"
0004 Action: End of block ""
(End)


Esc stops it and it (a) doesn't restart, and (b) doesn't crash Toolbox.

Change the parameter in line 1 by adding a pair of zeroes to the end, try again. This time, the loop stutters and continues until you hold Esc down and, once it's stopped, the crash happens.

Now do you see why I think it's a bug?

Paul (Lead Developer)

Quote from: oblivion on April 03, 2026, 01:43:05 PMNow do you see why I think it's a bug?
Found the issue (and it wasn't technically a bug). It's to do with resetting the auto-complete function of Toolbox. It gets disabled when a macro is run so that the macro doesn't auto-complete anything, and then resets when the macro is done; but this reset wasn't expecting a macro to be run thousands of times repeatedly. You never know what a user will come up with. :) I'll have to make it not reset if an action is currently inside a loop, and only reset once out of it.

oblivion


I was starting to think it was something external to Toolbox meaning me seeing something different to you! Thanks for confirming the issue :) 

And yes, sometimes I probably am that annoying edge case. If that's the phrase. :D

Paul (Lead Developer)

Hi oblivion. I just sent you an email with a new test version that should stop the Esc key crashing the app. Well, it stops it here. :) Please reply here with how it goes for you. Thanks!

oblivion

Thanks, Paul, I'll give it a go.

It's still bugging me slightly that Esc fails in a forever loop even if it's pressed more or less straight away, but doesn't fail in a finite (say 5000) loop whenever it's pressed. But I'll try the update and see what happens. :)

(Might not be today, though, we're going to see some flavour of Queen tribute act in a bit and probably not worrying about loops very much during it!)