Tuesday, December 16, 2014

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


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.


Answer



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.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...