0
votes

I want to be able to toggle my Hotkeys on and off. I have Hotkey mapping like "a=f" or "d=y". I want to be able to press one key and toggle "a=a" to "a=f" and back. Right now I am using the Suspend key for that. The problem is: when I want to Unsuspend I have to do this manually with my mouse and a right click to Unsuspend (because my custom hotkeys aren't running anymore, so the key that I have, that would unsuspend is not recognized because the script is suspended).

My simple idea would be a global hotkey for suspend and suspend. But I haven't found anything like that.

Therefore I made a boolean flag to toggle manually. For that I shouldn't need to suspend. But just have a key, that toggles the flag. Here is some example code:

    if (flag) 
    {   
        a::f 
    } 
    else 
    {   
        a::a 
    }

I get the duplicate hotkey error.

1
I don't know the syntax but you might try something like a:: if(flag) {f} else {a}Dan D.

1 Answers

1
votes

Toggling a variable's value:

flag := !flag

will make flag either true or false depending on its current value. True becomes false and vice versa.

flag := false ; initialize variable

F1:: flag := !flag ; press F1 to toggle the variable's value to true/false


; The #If-directive creates context-sensitive hotkeys and hotstrings:

#If (flag) ; if this variable has the value "true"

    a::f

#If ; turn off context sensitivity

https://autohotkey.com/docs/commands/_If.htm https://autohotkey.com/docs/Variables.htm#Expressions