This is a function made for the sole intention of executing other AHK commands. It is currently capable of running almost every AHK command which is practical to run dynamically. See the full list below. The basic idea is that the function will return the OutputVar, if any, or simply execute the given command. If there is more than one OutputVar, they are instead stored in the global array "r". (There are 7 variables in the array) For instance, ControlGetPos would store X in r1, Y in r2, Width in r3, and Height in r4. Also note that ErrorLevel is set globally. When a command has one or more OutputVars, those parameters are not just ignored, they're excluded. That is, the first parameter of the function (other than the "command" parameter) corresponds to the first non-OutputVar parameter in the command. For instance, the first parameter passed when ControlGetPos is the command would correspond to the Control parameter. The FutureUse parameter in InputBox is also skipped over this way.
Also note that due to containing Gui, Hotkey, and other related commands, this function will automatically make a script persistent.
The syntax for this function is:
Execute("Command","Parameter... 1","2","3","4","5","6","7","8","9","10","11")
For example:
execute(mycmd,param1[1] + param1[2],param2)
execute("msgbox","It works!")
Here is a list of commands currently supported. If there is no note beside a command, it conforms with the rules specified above. Also, any commands that use OutputVar will not use the "r" array unless specified here.
AutoTrim
BlockInput
ClipWait
Control
ControlClick
ControlFocus
ControlGet
ControlGetFocus
ControlGetPos: Uses the "r" array.
ControlGetText
ControlMove
ControlSend
ControlSendRaw
ControlSetText
CoordMode
DetectHiddenText
DetectHiddenWindows
Drive
DriveGet
DriveSpaceFree
Edit
EnvAdd
EnvDiv
EnvMult
EnvSet
EnvSub
EnvUpdate
ExitApp
FileAppend
FileCopy
FileCopyDir
FileCreateDir
FileCreateShortcut
FileDelete
FileGetAttrib
FileGetShortcut: Uses the "r" array. (All seven!)
FileGetSize
FileGetTime
FileGetVersion
FileMove
FileMoveDir
FileRead
FileReadLine
FileRecycle
FileRecycleEmpty
FileRemoveDir
FileSelectFile
FileSelectFolder
FileSetAttrib
FileSetTime
GetKeyState
GroupActivate
GroupAdd
GroupClose
GroupDeactivate
Gui
GuiControl
GuiControlGet
Hotkey
IfEqual: Uses a special method of returning; it returns 1 (true) if the If statement was evaluated to true or 0 (false) if it wasn't.
IfNotEqual: See note for IfEqual.
IfExist: See note for IfEqual.
IfNotExist: See note for IfEqual.
IfGreater: See note for IfEqual.
IfGreaterOrEqual: See note for IfEqual.
IfInString: See note for IfEqual.
IfNotInString: See note for IfEqual.
IfLess: See Note for IfEqual.
IfLessOrEqual: See note for IfEqual.
IfMsgBox: See note for IfEqual.
IfWinActive: See note for IfEqual. Also note that the built-in function WinActive() may be an option too.
IfWinNotActive: See note for IfWinActive.
IfWinExist: See note for IfEqual. Also note that the built-in function WinExist() may be an option too.
IfWinNotExist: See note for IfWinExist.
ImageSearch: Uses the "r" array.
IniDelete
IniRead
IniWrite
Input
InputBox: Skips over the FutureUse parameter. (In other words, TimeOut is in the eighth field, not Font)
KeyHistory
KeyWait
ListHotkeys
ListLines
ListVars
Menu
MouseClick
MouseClickDrag
MouseGetPos: Uses the "r" array.
MouseMove
MsgBox: Has special handling for parameters. If only one parameter is detected (non-false, meaning not blank or zero), it will run it that way, so the command can do automatic comma detection. If two or three are detected, it will run it in full-parameter mode, but without parameter four. If all parameters are detected, all parameters will be included in the command.
OnExit
OutputDebug
Pause
PixelGetColor
PixelSearch: Uses the "r" array.
PostMessage
Process
Progress
Random
RegDelete
RegRead: The obsolete 5-param method is not supported.
RegWrite
Reload
Run
RunAs
RunWait
Send
SendRaw
SendMessage: This is currently the only command that will return the value of ErrorLevel (since it would be pointless for it to wait otherwise).
SetBatchLines
SetCapslockState
SetControlDelay
SetDefaultMouseSpeed
SetFormat
SetKeyDelay
SetMouseDelay
SetNumlockState
SetScrollLockState
SetStoreCapslockMode
SetTimer
SetTitleMatchMode
SetWinDelay
SetWorkingDir
Shutdown
Sleep
Sort
SoundBeep
SoundGet
SoundGetWaveVolume
SoundPlay
SoundSet
SoundSetWaveVolume
SplashImage
SplashTextOn
SplashTextOff
SplitPath: Uses the "r" array.
StatusBarGetText
StatusBarWait
StringCaseSense: Note! This will affect the case sensitivity of the primitive syntax checker in this function if on; it will not work unless they are written exactly as they are here, with cameling (StringCaseSense would be allowed through, stringcasesense wouldn't). This also goes for any external use of this command.
StringGetPos
StringLeft
StringLen
StringLower
StringMid
StringReplace
StringRight
StringSplit: The Output* parameter in this one is not like other ones, and it counts as a parameter for the purposes of this function.
StringTrimLeft
StringTrimRight
StringUpper
Suspend: Permit is already set in the function, so this command can be safely used.
SysGet
Thread
ToolTip
Transform
TrayTip
URLDownloadToFile
WinActivate
WinActivateBottom
WinClose
WinGetActiveStats: Uses the "r" array.
WinGetActiveTitle
WinGetClass
WinGet
WinGetPos
WinGetText
WinGetTitle
WinHide
WinKill
WinMaximize
WinMenuSelectItem
WinMinimize
WinMinimizeAll
WinMinimizeAllUndo
WinMove: Supports the 2-param mode.
WinRestore
WinSet
WinSetTitle
WinShow
WinWait
WinWaitActive
WinWaitClose
WinWaitNotActive
Download