Need help making this script quit 1000 clicks?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TWnewbie
Posts: 1
Joined: 23 Oct 2018, 20:09

Need help making this script quit 1000 clicks?

23 Oct 2018, 20:31

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Persistent
SetTimer, PressTheKey, 35712
Return

PressTheKey:
Click
sleep, 500
Click
Return
This is a quick script I wrote for an application I need. I am brand new to scripting, and AHK so I have decided to use this as a practical means to teach myself the very basics of it and try to expand on it. I am currently at a standstill, and any help would be appreciated. I am sure it is simple to do, but I can't for the life of me figure it out.

About this script and its future: I am planning to make numerous advances for this script, but this was the first iteration. So the entire function of this script is every 35 seconds, my mouse clicks, waits 500ms, then clicks again. It works for what I need it to do, which is click! Later I plan to make it much more complex. As an end result I would like it to move to a pre-determined location, click, wait, click, move to another location, etc. After I get that operational I would like to go a little deeper and start using some randomness, in which it clicks between a say ever 20-40 seconds. After that I want to go even further and instead of moving to position (xxx,yyy), I would like it to move to a random location inside of a small area, if that makes sense. I am a loooong way from this, but I am quite excited to learn this.

What I need help with: So the main problem I have at this point is I can't figure out how to make the script repeat 1,000 times then stop. It just seems to run on repeat forever. (I think this is because of the #Persistent at the top of the script?).

How I want it to function:
I would like to run the script manually (because making it start on its own seems impossible?).
Have the script perform its current code 1,000 times (click 1000 times, every 35 seconds, with a .500 sleep between the clicks.
After the 1,000th click, I would like it to stop, either via just stopping the clicks or closing the script either one.

I have tried Exit and ExitApp, but I don't think I am using them correctly, because it never stopped, and even if I did I don't know how to make it exit only after 1k clicks. I have tried google, reading a ton of other threads, and looking in the AHK.docs but this is kind of complicated for a first time seeing it. Thank you for any help. I hope to pick up more knowledge along the way!
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need help making this script quit 1000 clicks?

24 Oct 2018, 00:34

Hallo,
try:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Persistent
SetTimer, PressTheKey, 35712
No = 0
Return

PressTheKey:
Click
sleep, 500
Click
No++ ;Number of repetitions
If (No = 1000)
	ExitApp
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, filipemb, Rohwedder and 311 guests