Left click triggers left click and disables left click for 1 second

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Xproplayer
Posts: 24
Joined: 12 Feb 2017, 23:26

Left click triggers left click and disables left click for 1 second

12 Feb 2017, 23:32

I just want a script to only allow me to click once per second, need to practice not spamming left click in a video game.
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Left click triggers left click and disables left click for 1 second

13 Feb 2017, 01:03

Code: Select all

toggle := false ;script active only when toggled on
hotkey,~lbutton,click1,on ;this ties a hotkey to an event, in this case click1;  Note the ~ before the hotkey, this prevents the original click from being blocked by ahk
return ;return to idle

click1:
if (toggle) { ;if toggle is set to true/1 then 
	hotkey,lbutton,noclick,on ;change lbutton hotkey event to noclick which does nothing, no ~ = no original click
	settimer,resetclick,1000 ;set a timer to re enable click in 1000ms = 1 second
}
return

noclick: ;nothing happens here
return

resetclick: ;timer event
hotkey,~lbutton,click1,on  ;set the hotkey of left click back to click1 and start over
settimer,resetclick,off ;turn this timer off
return

f1::
toggle := !toggle ;turn script on/off;   toggle = the opposite of toggle so, on to off, off to on.
soundbeep ;play a simple beep to let you know the script is active
return

f8::exitapp  ;close the program
f9::reload ;reload the program
This should work for ya
Last edited by Spawnova on 13 Feb 2017, 01:18, edited 1 time in total.
Xproplayer
Posts: 24
Joined: 12 Feb 2017, 23:26

Re: Left click triggers left click and disables left click for 1 second

13 Feb 2017, 01:08

Spawnova wrote:

Code: Select all

toggle := false ;script active only when toggled on
hotkey,~lbutton,click1,on
return

click1:
if (toggle) {
	hotkey,lbutton,noclick,on ;blocks left click for 1 second
	settimer,resetclick,1000
}
return

noclick:
return

resetclick:
hotkey,~lbutton,click1,on  ;left click re enabled
settimer,resetclick,off
return

f1::
toggle := !toggle ;turn script on/off
soundbeep
return

f8::exitapp
f9::reload

This should work for ya
Wow this is in an entirely different format from the code I usually write, I'll give it a shot. Would you mind at all explaining how it works?
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Left click triggers left click and disables left click for 1 second

13 Feb 2017, 01:19

I've gone back and edited my first post with much more comments, if you still have questions let me know. =P
Xproplayer
Posts: 24
Joined: 12 Feb 2017, 23:26

Re: Left click triggers left click and disables left click for 1 second

22 Feb 2017, 16:46

Spawnova wrote:I've gone back and edited my first post with much more comments, if you still have questions let me know. =P
Hey followup, I'm loving this script, I want to make it so that its enabled by default as sometimes I disable it and forget to turn it back on, so I'm trying to do a loop every 5 minutes to set it back to enabled, but it doesn't seem to work,

I just added this code at the bottom:
Loop
{
toggle := 1
Sleep 300000
}

Can you tell me how to fix that code or how to do it properly?
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Left click triggers left click and disables left click for 1 second

22 Feb 2017, 19:15

Hello again, if you want the script enabled by default you can change toggle := false, to toggle := true at the top

If you want the script to turn itself back on if it's been toggled off, you could do something like this:

Code: Select all

toggle := false ;script active only when toggled on
resetTimer := 15 * 1000 ;if toggled off for 15 seconds, will toggle back to true
hotkey,~lbutton,click1,on
return

click1:
if (toggle) {
	hotkey,lbutton,noclick,on ;blocks left click for 1 second
	settimer,resetclick,1000
}
return

noclick:
return

resetclick:
hotkey,~lbutton,click1,on  ;left click re enabled
settimer,resetclick,off
return

reactivate:
goto toggleEvent ;this goes back to the toggle event, which will turn it on
return

f1::
toggleEvent:
toggle := !toggle ;turn script on/off
if (toggle)
	settimer,reactivate,off ;script is active so wait until its turn off
else
	settimer,reactivate,% resetTimer	 ;if toggled off set a timer to re enable script
soundbeep
return

f8::exitapp
f9::reload

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Spawnova and 123 guests