AutoIt Calculator
Aus ExpeccoWiki
Inhaltsverzeichnis |
Description
With AutoIt you can interact with all standard Windows GUIs. This example will demonstrate how to open the calculator. Then it performs some calculations by simulating mouse clicks and checks the result. Afterwards it closes the window.
Opening the Calculator
In order to open the calculator we have got to execute 'calc.exe'. This is done by the "AutoIt [ Run ]" block. It is given the file name of the executable. By using the "AutoIt [ RunAs ]" block you could also specify a user and a domain to execute the task. After the task is started, we have to wait for the window to become active. The "AutoIt [ WinWaitActive ]" block will pause the execution until the window has become active. Please note that the window title depends on the machine's language settings. For example, it is titled "Calculator" on English settings and "Rechner" on German ones.
Simulating Mouse Clicks
You can click on a control by using its internal name. For example, the '5' button is internally called 'Button10'. Please note that these button numbers change when the scientific calculator version is used. In order to customize the click simulation you can also specify a mouse button (e.g. 'left', 'middle' or 'right') or a number of clicks to simulate. In order to perform the calculation '5*5=' we have to click on the buttons '10' (5), '18' (*), '10' (5) and '21' (=). Therefore we use the "AutoIt [ ControlClick ]" block.
Checking the Result
Now we have to retrieve the displayed result from the control 'Edit1' and compare it to the expected result of 25. In order to do so we will use the "AutoIt [ GetText ]" block and the "Compare [ Equal 2-Way ]" block. Please note that there is also a comma displayed.
Closing the Window
Finally we close the calculator window using the "AutoIt [ WinClose ]" block.
Back to Examples.


