0
votes

My script should check for the value of a variable, if it's 0, it should remap some keys, if the value is not 0, it should not remap any key, or run any of the hotkeys: (my variable is called chatbox)

#IfWinActive Minecraft 1.8.9
  If (ChatBox = 0){
    1::z
  }
#IfWinActive

But it doesn't work! AHK doesn't check the variable:

---- C:\Users\...\mysimplescript.ahk
157: SPI_SETDEFAULTINPUTLANG := 0x005A
157: SPIF_SENDWININICHANGE := 2
030: Return (3.41)
263: Send,z (0.02)
263: Return (2.50)

Why don't I use the if statement inside the hotkey? I did! the problem is, it doesn't really work with games, it's just probably how Windows works, I tried this:

1::
  If (ChatBox = 0)
    send z
  else
    send 1
return

I don't want to use an if statement inside a hotkey, my question is, I want certain hotkeys to get activated with change of a variable.

1

1 Answers

2
votes

This conditionally executes a hotkey based on a variable:

#If ChatBox = 0
  1::z
#If

This conditionally executes a hotkey based on a variable and window:

#If WinActive("Minecraft 1.8.9") and ChatBox = 0
  1::z
#If

REF: https://autohotkey.com/docs/commands/_If.htm