Help with toggle function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ViniBraz
Posts: 2
Joined: 25 Apr 2024, 08:06

Help with toggle function

25 Apr 2024, 08:43

I have a script for left click mouse toggle and it works just fine...
the problem is, if I try to add another button to hold pressed as the clicks continue, it messes with the toggle and it doesnt "untoggle" anymore.

This one works just fine:
Spoiler
.....................

But this one starts the looping but it doesnt end when I press the key again, it never ends
Spoiler

What I want is for the "Ctrl" key to be pressed down as the script loops... and releases when I toggle off the script.
What am I doing wrong?
User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: Help with toggle function

25 Apr 2024, 13:28

Welcome to this AutoHotkey forum!

If you need to trigger a hotkey while a modifier is being held, then you must do at least one of three things.
  1. Add the modifier to the hotkey.
  2. Add the wildcard to the hotkey.
  3. Use a custom combination (not usually preferred).

Code: Select all

#Requires AutoHotkey v1.1.33.11
#MaxThreadsPerHotkey 2

LButton::
#If on
^LButton::
on := True
Send {Ctrl down}
ToolTip % A_ThisHotkey
SoundBeep 1500
Sleep 2000
SoundBeep 1000
Send {Ctrl up}
ToolTip
on := False
Return
#If
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
ViniBraz
Posts: 2
Joined: 25 Apr 2024, 08:06

Re: Help with toggle function

26 Apr 2024, 06:32

doesnt work
how do you combine this with my working script?
the question is simple:
I want to toggle a little looping script on and off by pressing a button

this script:

Code: Select all

		Send {Ctrl down}
		Click, Down
		Sleep 1800
		Click, Up
		Sleep 3
		Send {Ctrl up}
whenever i press the button it should start looping, and stop when i press again the same button
User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: Help with toggle function

26 Apr 2024, 08:29

This forum has thousands of posts with toggles. Another is below. Test in Notepad.

Code: Select all

#Requires AutoHotkey v1.1.33.11
#MaxThreadsPerHotkey 2

F3::
#If on
^F3::
on := !on
While on {
 Send {Ctrl down}{LButton down}
 Loop 8
  Sleep 225 * on
 Send {LButton up}{Ctrl up}
}
Return
#If

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, peter_ahk and 99 guests