Left click triggers left click and disables left click for 1 second
-
- Posts: 24
- Joined: 12 Feb 2017, 23:26
Left click triggers left click and disables left click for 1 second
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.
Re: Left click triggers left click and disables left click for 1 second
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
Last edited by Spawnova on 13 Feb 2017, 01:18, edited 1 time in total.
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
-
- Posts: 24
- Joined: 12 Feb 2017, 23:26
Re: Left click triggers left click and disables left click for 1 second
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?Spawnova wrote:This should work for yaCode: 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
Re: Left click triggers left click and disables left click for 1 second
I've gone back and edited my first post with much more comments, if you still have questions let me know. =P
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
-
- Posts: 24
- Joined: 12 Feb 2017, 23:26
Re: Left click triggers left click and disables left click for 1 second
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,Spawnova wrote:I've gone back and edited my first post with much more comments, if you still have questions let me know. =P
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?
Re: Left click triggers left click and disables left click for 1 second
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:
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
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
Who is online
Users browsing this forum: Spawnova and 123 guests