Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoHotKey Global Variable that can be accessed and modified by different macros?

I've seen a similar topic on sof but its solution did not help me. This is ticking my mind and basically all i want is to have some method of accessing and modifying a value that will maintain its last changed state through out my macros in my single .ahk file.

See example below ,

~Home::Suspend

XButton1::

tog()

return

LButton::

shot()

return



var := "1"

tog(){
var *= -1
}

shot(){

If (var = "1") {

    Loop, 1 {

        Send {k}
        Sleep 65
        Send {WheelDown}
        Sleep 100
        Send {WheelUP}
        Sleep 10

    }

} Else {

    Send {k}

}

}

I am aware that the above is incorrect, and i tried to use"global" in my functions but i just couldn't get my desired effect.

like image 559
matiszac Avatar asked Dec 21 '22 15:12

matiszac


1 Answers

Using the "global" should work. Something like:

shot(){
    global var
    If (var = "1") {

That points the 'var' variable in the shot() function to the existing 'var' variable defined outside the function.

like image 174
Ani Avatar answered May 16 '23 01:05

Ani