Autoitx is provided by autoit3 for otherProgramming LanguageAnd a component of the development environment. This component supports ActiveX, COM, and DLL calls. Therefore, based on the feature of autoit3, you can get rid of its own development environment and use the programming environment that you are good at to call autoitx to assist in automated testing tasks. I personally think this is an improvement, and it is also a good news for fans of tools.
The following is a simple example of using autoitx in C.
Environment ide: Visual studio2010
Create a consol application project, open the reference Panel of the function, and select autoitx3 Type Library in COM.
InCodeUse the namespace of autoitx: Using autoitx3lib;
Then a new autoitx3class class instance can call functions such as controlclick.
The sample code is as follows:
Using system; Using system. Collections. Generic; Using system. LINQ; Using system. text; Using autoitx3lib; Namespace autoitxtest { Class Program { Static void main (string [] ARGs) { Autoitx3lib. autoitx3class AI = new autoitx3class (); AI. Run (@ "calc.exe "); AI. winactivate ("[Class: scic1c]"); AI. controlclick ("", "", "[ID: 125]"); } } } |
The members of the autoitx3class class can view the following in the Object Browser. Here we can see the methods exposed by autoitx.
You can also useP/invokeIn the managed code, the static method is used. It is shown as follows. Note that the dllimport autoitx. dll has a 64-bit version, which are:
C: \ Program Files \ autoit3 \ autoitx \ autoitx3.dll or 64-bit version --
C: \ Program Files \ autoit3 \ autoitx \ autoitx3_x64.dll
Using system; Using system. Collections. Generic; Using system. LINQ; Using system. text; Using system. runtime. interopservices; Namespace autoitxtest { Class Program { Public const int sw_show = 6; Public const int sw_showdefault = 7; Public const int sw_showmaximized = 8; Public const int sw_showminimized = 9; [Dllimport ("autoitx3.dll", setlasterror = true, charset = charset. Auto)] Static public extern int au3_controlclick ([financialas (unmanagedtype. lpwstr)] String title , [Financialas (unmanagedtype. lpwstr)] string text, [financialas (unmanagedtype. lpwstr)] String Control , [Financialas (unmanagedtype. lpwstr)] string button, int numclicks, int X, int y ); [Dllimport ("autoitx3.dll", setlasterror = true, charset = charset. Auto)] Static public extern int au3_run ([financialas (unmanagedtype. lpwstr)] string run , [Financialas (unmanagedtype. lpwstr)] string Dir, int showflags ); [Dllimport ("autoitx3.dll", setlasterror = true, charset = charset. Auto)] Static public extern void au3_winactivate ([financialas (unmanagedtype. lpwstr)] String title , [Financialas (unmanagedtype. lpwstr)] string text ); [Dllimport ("autoitx3.dll", setlasterror = true, charset = charset. Auto)] Static public extern void au3_sleep (INT milliseconds ); |
:
Static void main (string [] ARGs) { Au3_run ("calc.exe", "", sw_showmaximized ); Au3_winactivate ("[Class: scic1c]", ""); Au3_sleep (2000 ); Au3_controlclick ("", "", "[ID: 125]", "", 1, 0, 0 ); Au3_controlclick ("", "", "[ID: 125]", "", 1, 0, 0 ); Au3_controlclick ("", "", "[ID: 125]", "", 1, 0, 0 ); } |
Code:
The only explanation is that the list of static methods of dllimport can be found in the autoitx help document.
In VBScript, The autoitx function is used to create a COM object. The following is a code Demonstration:
Set oshell = wscript. Createobject ("wscript. Shell ") Set oautoit = wscript. Createobject ("autoitx3.control ") Oshell. Run "calc.exe", 1, false Oautoit. winwaitactive "[Class: scic1c]", "" Oautoit. Send "1 {+} 1 =" |
So what COM objects does autoitx provide for use? For more information, see the autoitx help document. Here we only list the directories: