0
votes

I want this Autohotkey script to press the spacebar automatically with a toggle option so i dont have to hold the spacebar all the time. The toggle key should be the middle mouse button. Could you please write it correctly for me? Because the toggle part I found doesn't seem to work. Thanks in advance CptPrice :D

Main script:
*~$Space::
Sleep 100
Loop
{
GetKeyState, SpaceState, Space, P
If SpaceState = U
break
Sleep 5
Send, {Blind}{Space}
}

Toggle-part:

#MaxThreadsPerHotkey 2   

MButton::
if (toggle := !toggle) {
    ; on
} else {
    ; off
}
return
1

1 Answers

2
votes
toggle := false
return

MButton:: toggle := !toggle

#If toggle

#MaxThreadsPerHotkey 2

*~$Space::
Sleep 100
Loop 
{
Sleep 5
Send, {Blind}{Space}
    if (!toggle)        ; Press MButton to break
        break
}
return

#If