Autohotkey - set a hotkey to toggle (disabled-enabled a hole autohotkey script)

0

Hi I used to use at the beginning of my Autohotkey script toggle between totally disable it and totally enable it scrolllock:: Pause

but it doesn't work anymore, and I have realize that if I set it, it will not let me set variables. e.g.

scrolllock:: Pause
var := 29    ; <--- this var will not be set cuz the line above

It will only be set if I remove the line above, I have tested it.

I have tried to change it to...

f12::
Pause
Suspend
return

but it doesn't work with the scrollock key I guess I need to set a keystate

How can I do this, thanks Advanced.

litu16

Posted 2016-11-21T14:49:23.413

Reputation: 143

Answers

2

This code will never run

scrolllock:: Pause

var := 29 

F1:: MsgBox, %var%

because you try to set a variable between hotkeys.

A variable has to be defined in the auto executable section of the script (top of the script, before the first return or hotkey)

; top of the script:
var := 29
    return      ; end of auto-execute section

scrolllock:: Pause

F1:: MsgBox, %var%

or in a hotkey

scrolllock:: Pause

F1:: 
var := 29
MsgBox, %var%
return 

or in a function.

user3419297

Posted 2016-11-21T14:49:23.413

Reputation: 2 055

Hi user3419297 once the AHK script is running, I use the hotkey (scroll Lock) to pause it, but its hotkeys are still functional (they are still working) so if I press space & e I get the script to run some actions. I have noticed that the hotkeys trully get disabled only when I right click the AHK script icon on the taskbar and choose Suspend Hotkyes I would like suspend and renabled AHK hotkeys using the scroll Look key. Hot can I do taht?? – litu16 – 2016-11-28T00:08:47.217

Replace "scrolllock:: Pause" with "scrolllock:: Suspend". – user3419297 – 2016-11-28T08:00:53.127

0

AHK One-Liners

Just place Pause on a new line and add a return statement.

scrolllock:: Pause ; <-- Quick One-liner Script
    var := 29      ; <-- Not executed

scrolllock:: ; <-- Full Script
    Pause
    var := 29
    return   ; <-- Explicit return statement needed

If you have code on the first line, AHK will assume it is a quick one-liner and add in implicit return at the end. So var := 29 after it won't be executed.

NonlinearFruit

Posted 2016-11-21T14:49:23.413

Reputation: 738

hi NonlinearFruit thanks for your answer, can an question have two answers?? please I currently have a question here http://superuser.com/questions/1149519/use-space-alt-q-to-trigger-some-actions-in-autohotkey hope you could check it out, thanks advanced.

– litu16 – 2016-11-24T21:59:07.593

@litu16 You can only accept one answer. Here are guidelines for accepting and up-voting answers.

– NonlinearFruit – 2016-11-25T02:11:30.380

ok thanks, this question was answered before, thanks anyway. – litu16 – 2016-11-25T05:14:54.823