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.

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.

2
  • 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 Nov 28 '16 at 0:08
  • Replace "scrolllock:: Pause" with "scrolllock:: Suspend". – user3419297 Nov 28 '16 at 8:00
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.

3
  • hi NonlinearFruit thanks for your answer, can an question have two answers?? please I currently have a question here superuser.com/questions/1149519/… hope you could check it out, thanks advanced. – litu16 Nov 24 '16 at 21:59
  • @litu16 You can only accept one answer. Here are guidelines for accepting and up-voting answers. – NonlinearFruit Nov 25 '16 at 2:11
  • ok thanks, this question was answered before, thanks anyway. – litu16 Nov 25 '16 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.