Jump to content

Is it possible? (Run a function with AutoIt3ExecuteLine)


 Share

Recommended Posts

I want to make a function that takes another function's name (and even parameters) as parameter and run it with AutoIt3ExecuteLine.

Maybe something similar to this:

_ExecuteFunc('_MoveMouse(10, 10)')

Func _MoveMouse($X, $Y)
MouseMove($X, $Y)
EndFunc

Func _ExecuteFunc($Func)
Run(@AutoItExe & ' /AutoIt3ExecuteLine $Func')
EndFunc
Edited by D4RKON3
Link to comment
Share on other sites

I usually call functions directly (not with AutoITExecuteLine).

I define the values and then pass them via a call like

$runcommand = "C:ProgrammeAutoIt3orderwindow.exe" & " " & $tradeAccount & " " & $currentpair & " " & $action & " " & $orderTradeUnits & " " & $__CurrentPrice & " " & $setTP & " " & $TPvalue & " " & $setSL & " " & $SLvalue
ConsoleWrite("- " & @ScriptLineNumber & " parameters:" & " $tradeAccount " & $tradeAccount & ", $currentpair:" & $currentpair & ", $action:" & $action & ", $orderTradeUnits:" & $orderTradeUnits & " $__CurrentPrice:" & $__CurrentPrice & " $setTP:" & $setTP & " $TPvalue:" & $TPvalue & " $setSL:" & $setSL & " $SLvalue:" & $SLvalue & @CRLF)
Run($runcommand)
Edited by guwguw
Link to comment
Share on other sites

I want to make a function that takes another function's name (and even parameters) as parameter and run it with AutoIt3ExecuteLine.

Maybe something similar to this:

_ExecuteFunc('_MoveMouse(10, 10)')

Func _MoveMouse($X, $Y)
MouseMove($X, $Y)
EndFunc

Func _ExecuteFunc($Func)
Run(@AutoItExe & ' /AutoIt3ExecuteLine $Func')
EndFunc

Here is an example using message boxes but you can change it to whatever you need.

If $CMDLINE[0] > 0 then

If $CMDLINE[1] = "_MyExternallyRanFunction()" then
_MyExternallyRanFunction()
Exit
EndIf

EndIf


_RunExternal("_MyExternallyRanFunction()")

MsgBox(0,"Msgbox1","I am running from the main script!" & @crlf & "My PID = " & @AutoItPID)



Func _RunExternal($COMMAND)

If @Compiled then
Run('"' & @ScriptFullPath & '" ' & $COMMAND, @ScriptDir)
Else
Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" ' & $COMMAND,@ScriptDir)
EndIf


EndFunc


Func _MyExternallyRanFunction()


Msgbox(0,"Msgbox2","I am the message box running in an external process" & @crlf & "My PID = " & @AutoItPID)

EndFunc
Link to comment
Share on other sites

With the help of ChrisL i made this so far that is suitable for my usage.

Just want to share, maybe someone find it useful.

_FuncAsProcess.au3

If $CMDLINE[0] Then
Call($CMDLINE[1])
Exit
EndIf
Func _FuncAsProcess($Function)
If @Compiled Then
  Return Run('"' & @ScriptFullPath & '" ' & $Function, @ScriptDir)
Else
  Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" ' & $Function, @ScriptDir)
EndIf
EndFunc

_FuncAsProcess Example

#NoTrayIcon
#include <_FuncAsProcess.au3>

GUICreate('_FuncAsProcess', 250, 100)
$chkEnable = GUICtrlCreateCheckbox('Enable Loop', 10, 10)
GUISetState()

While True
Switch GUIGetMsg()
Case -3
Exit
Case $chkEnable
If GuiCtrlRead($chkEnable) = 1 Then
$ProcessID = _FuncAsProcess('_StartLoop')
Else
ProcessClose($ProcessID)
EndIf
EndSwitch
WEnd

Func _StartLoop()
$i = 1

While $i > 0
ToolTip($i)
$i += 1
Sleep(10)
WEnd
EndFunc
Edited by D4RKON3
Link to comment
Share on other sites

You can change this a little and also use parameters if you need to.

If $CMDLINE[0] > 0 then

  Switch $CMDLINE[0]
     Case 1
        Call($CMDLINE[1])
    Case 2
        Call($CMDLINE[1],$CMDLINE[2])
    Case 3
        Call($CMDLINE[1],$CMDLINE[2],$CMDLINE[3])
    Case 4
        Call($CMDLINE[1],$CMDLINE[2],$CMDLINE[3],$CMDLINE[4])
    Case 5
        Call($CMDLINE[1],$CMDLINE[2],$CMDLINE[3],$CMDLINE[4],$CMDLINE[5])
    Case Else
       ;
 EndSwitch

Exit

EndIf


_RunExternal("_MyExternallyRanFunction")
_RunExternal("_MyExternallyRanFunction",'"I have 1 param"')
_RunExternal("_MyExternallyRanFunction",'"I have 2 params" "See this is my Second param"')
_RunExternal("_MyExternallyRanFunction",'"I have 3 params" "This is my Second param" "And this is my Third param"')
_RunExternal("_MyExternallyRanFunction",'"I have 4 params" "This is my Second param" "This is my Third param" "Look it''s my Fourth param"')

MsgBox(0,"Msgbox1","I am running from the main script!" & @crlf & "My PID = " & @AutoItPID)



Func _RunExternal($COMMAND,$Param = "")

  If @Compiled then
    Run('"' & @ScriptFullPath & '" ' & $COMMAND & " " & $Param, @ScriptDir)
  Else
    Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" ' & $COMMAND & " " & $Param,@ScriptDir)
  EndIf

EndFunc


Func _MyExternallyRanFunction($param1="",$param2="",$param3="",$param4="")

  Msgbox(0,"Msgbox2","I am the message box running in an external process" & @crlf & "My PID = " & @AutoItPID & @CRLF & $param1 & @CRLF & $param2 & @CRLF & $param3 & @CRLF & $param4)

EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...