Preface for AutoHotkey v1.1
In Autohotkey scripts virtually any parameter wich supports expressions can be extended. I didn't found this in docs. First I applied it when using Ternary operator e.g.: a? (b:=1, c:=0): (b:=0, c:=1), then I started to use it spontaneously alongside other parameters and suddenly I noticed it works everywhere.
See additional example (I wasn't aware of) by Rohwedder too!
Note: First parameter is considered as a native one!
As for every fee code and especially for this one: Test it and then use it at your own risk!
If (expression)
Code: Select all
a:= 0, b:= 0, c:= 4, d:= 5
loop, 2
if (a<b, A_Index=1? b:=1: b:=-1, c++, d++)
MsgBox % "Yes for the second turn even if the b is " b "`nwhile c: " c " and d: " d " are alway incremented"
else MsgBox % "No even if b is " b "`nwhile c: " c " and d: " d " are alway incremented"
loop
if (A_Index>5? v:="Breaking the Loop occurred at iteration": "", l:=A_Index)
Break
MsgBox % v " : " l
ExitApp
Code: Select all
a:= 3
loop, % (a, b:=4, c:=5)
if A_Index = 1
MsgBox % "a = " a
else if A_Index = 2
MsgBox % "b = " b
else if A_Index = 3
MsgBox % "c = " c
SoundBeep
loop, parse, % ("abc", a:=1, b:=2, c:=3) ; Note "parse" won't except extended parametrs
if A_Index = 1
MsgBox % A_LoopField " = " a
else if A_Index = 2
MsgBox % A_LoopField " = " b
else if A_Index = 3
MsgBox % A_LoopField " = " c
SoundBeep
loop, parse, % ("a`nb`nc", a:=1, b:=2, c:=3), % ("`n", d:=4)
if A_Index = 1
MsgBox % A_LoopField " = " a
else if A_Index = 2
MsgBox % A_LoopField " = " b
else if A_Index = 3
MsgBox % A_LoopField " = " c
MsgBox % "d = " d
ExitApp
Code: Select all
a:= 3
while (a>0, b:=1, c:=A_Index, a-=b) ;Note, that the third MsgBox appears despite a is beeing set to 0
MsgBox % "a: " a "`nb: " b "`nc: " c
ExitApp
Code: Select all
r:= [7, 8, 9]
for i, j in (r, b:=0, b+=1) ; parametr(s) are parsed only once
MsgBox % "b is always: " b "`n" "j: " j
Code: Select all
Random, Rn1, 1, (9, a:=11, b:=22) ; variable name of additional paramter may not be the same as the variable
Random, Rn2, (1, c:=33, d:=44), 9 ; to store random value, or it will be overwritten by Random command
Random, Rn3, (1, e:=55, f:=66), (9, g:=77, h:=88)
random, Rn4, (i:=a, i+=988), (j:=b, j+= 978) ; note that chanage of the value effects the outcome immediately
MsgBox % Rn1 "; " a ", " b "`n" Rn2 "; " c ", " d "`n" Rn3 "; " e ", " f ", " g ", " h "`nHowever: " Rn4 "; " i ", " j
ExitApp
Code: Select all
SetTimer, T, % (1000, a:=0, b:=10)
Return
Esc::ExitApp
T() {
Global
ToolTip % ++a ", " ++b
Sleep 500
ToolTip
}
Code: Select all
Global c:= 0
a:= 0, b:= 6
loop, 3
MsgBox % f((a, c+=b), (b, b-=++a))
SoundBeep
ExitApp
f(a, b) {
Return "a: " a "`nb: " b "`nc: " c
}
Code: Select all
Gui, Add, % ("Edit", a:=9), % ("w200 h150 vEdt", whEdt:="w300 h250")
, % ("You can extend any parameter wich supports expressions!", SwitchEdt:=1)
Gui, Show, % ("", xyGui:= " x350 y350 ", whGui:=" w320 h265 ")
Sleep, % (1000, SwitchGui:=1)
if SwitchGui && SwitchEdt {
GuiControl, Move, Edt, % whEdt
Gui, Show, % xyGui whGui
}
MsgBox % "Varaible a is: " a
ExitApp
Return
GuiClose:
GuiEscape:
ExitApp
Exemples for AutoHotkey v2.0