0

I found a way to run built in auto it functions from python using the following code

from win32com.client import Dispatch
Auto = Dispatch("AutoItX3.Control")
Auto.Run("notepad.exe", "", 5)

Is there a similar way to call custom methods i.e methods defined in my_AutoIt_File.au3 Say I have a method in this file

Func my_autoit_method
   ;some code
EndFunc

Is there a way to call this my_autoit_method from python?

1
  • Maybe the documentation of AutoItX3.Control can tell you that. Commented Jun 13, 2014 at 20:07

2 Answers 2

1

From the help file:

AutoIt specific command Line Switches

  • Form1: AutoIt3.exe [/ErrorStdOut] [/AutoIt3ExecuteScript] file
    [params ...]

               Execute an AutoIt3 Script File
    

/ErrorStdOut Allows to redirect fatal error to StdOut which can be captured by an application as Scite editor. This switch can be used with a compiled script.

To execute a standard AutoIt Script File 'myscript.au3', use the command: 'AutoIt3.exe myscript.au3'

  • Form2: Compiled.exe [/ErrorStdOut] [params ...]

            Execute an compiled AutoIt3 Script File produced with Aut2Exe.
    
  • Form3: Compiled.exe [/ErrorStdOut] [/AutoIt3ExecuteScript file] [params ...]

            Execute another script file from a compiled AutoIt3 Script File. Then you don't need to fileinstall another copy of AutoIT3.exe in your compiled file.
    
  • Form4: AutoIt3.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line"

            Execute one line of code.
    

To execute a single line of code, use the command:

Run(@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(0, ''Hello World!'', ''Hi!'')"')
Sign up to request clarification or add additional context in comments.

Comments

1

You have to expose your AutoIt Function to other applications. This could be done easily with AutoItObject, which can register an object in the ROT.

The AutoIt Code would be:

#include <AutoItObject.au3>

$oObject = _AutoItObject_Create()
_AutoItObject_RegisterObject($oObject, 'MyVery.CustomApplication')
_AutoItObject_AddMethod($oObject, '_my_custom_function', '_my_custom_function')

While Sleep(100)
WEnd

Func _my_custom_function($oSelf)
    MsgBox(0, '', 'AutoIt says Hi')
    Exit
EndFunc

The Python Code should be:

from win32com.client import Dispatch
Auto = Dispatch("MyVery.CustomApplication")
Auto._my_custom_function()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.