Turning a script on and off

Ask gaming related questions (AHK v1.1 and older)
CyborgManatee
Posts: 4
Joined: 24 Mar 2017, 18:34

Turning a script on and off

24 Mar 2017, 18:50

I'm wondering if there is a way to use a key to activate/toggle a script instead of having to manually stop it from working every time you want to do so. Basically I want to be able to press R (as an example) to turn the following script on and off:

Code: Select all

z::a
Return

x::d
Return
Can you do that within the same script? Right now I have to go to the taskbar and right-click the script and select "Suspend Hotkeys" but I would rather be able to just press a key (using R as my example) to toggle it on and off.

(In case it matters, I've compiled the script into a .exe)
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Turning a script on and off

24 Mar 2017, 19:35

Code: Select all

^!s:: ; CTRL+ALT+S
Suspend
return
(see: https://autohotkey.com/docs/commands/Suspend.htm)

EDIT:
see also ExitApp command (which command instead of Suspend -- wich one disable or enable hotkeys and hotstrings -- allows exit the script : https://autohotkey.com/docs/commands/ExitApp.htm)

Code: Select all

^!x:: ; CTRL+ALT+X
ExitApp
my scripts
User avatar
Spawnova
Posts: 555
Joined: 08 Jul 2015, 00:12
Contact:

Re: Turning a script on and off

27 Mar 2017, 02:45

Here's another method using a variable, this can be useful for when you want to disable hotkeys but keep the script running.

Code: Select all

toggle := true
return

f1::toggle := !toggle   ;inverts toggle 0>1>0>1 etc.

#If toggle ;if toggle = true/1 then hotkeys work, otherwise disabled
z::a  ;this does not need a return since its single line
x::d

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 77 guests