I wanted to bring back this topic to live: Execute AHK code dynamically! My function does quite the same but in a little different way and it offers additionally a small debug feature as well as one line if statements, such as IfEqual, IfGreater, IfExist, IfWinActive...:
Code:
#("IfWinActive", "ahk_class ExploreWClass","","","","MsgBox", WinExist())
If var ">|<|=|is|is not" is also used that way:
Code:
#("If", "var", "is", "digit","MsgBox")
As far as I understand, using this function performance is not affected at all, at least using new AutoHotkey.exe beta. All commands excluding loop commands and Return are supported. Instead of Return use Exit
Code:
#("Command", "parameter1","parameter2",...) ;Each command has an abbreviation: ; Sleep= S, Send = SN, IfWinActive = IWA, IfExist = IE,IfEqual = IEQ, ControlGet = CG,...
Using this function you can execute many commands in one line.
Code:
;Instead of: Loop, C:\*.txt,0,1 { command command command } ;you can do Loop, C:\*.txt,0,1 #("command") #("command") #("command")
Instead of If expression you can use ? : (Ternary operator [v1.0.46+]) For example:
Code:
debug := WinExist("ahk_class ExploreWClass") ? #("WinActivate","ahk_class ExploreWClass") : #("Run","explorer /e") MsgBox % debug
Small debuging feature:
Code:
Such commands, that change the variable ErrorLevel, use this SubCommand to return a value for debuging: Return: Return A_Tab . "ErrorLevel: " . Errorlevel . "`t" . p1 . "," . p2 . "," . p3 . "," . p4 . "," . p5 . "," . p6 . "," . p7 . "," . p8 . "," . p9 . "," . p10 . "," . p11 . "," . p12 . "," . p13 . "," . p14 . "," . p15 . "," . p16 . "," . p17 . "," . p18 . "," . p19 . "," . p20 "`n" ;Change this line to your needs, include parameters as well as AutoHotKey variables like ErrorLevel, A_Index, A_LoopField,...
You can also add your custom functions as if they were commands (look at PixelWaitColor command in the code) If you find any errors or you have a suggestion, please post