Wednesday, August 3, 2011

Getting Familiar with AutoIt3 Window Info Tool


AutoIt Website: https://www.autoitscript.com

Hello everyone. In this tutorial, I will help you to get familiar with a very useful tool that was integrated with the full installation package of AutoIt3. The tool I'm talking about is called (AutoIt Window Info), and the following image show where you can locate its shortcut to run it. Let's run this tool, and discover its importance in developing AutoIt3 scripts.



After running the AutoIt Window Info program, you will get a window below.


The use of this program is very simple, plus it's considered as a big help in writing AutoIt3 scripts. The most important tool in this program is the (Finder Tool) as it's labeled below.


The job of this Finder Tool is to retrieve information about programs windows, and controls inside the windows. To understand more, let me demonstrate an example. Let's try to use the Finder Tool on the calculator program that is integrated with Windows OS. This is the calculator program window.


Now, we want to get information about the calculator program window using Finder Tool which is in AutoIt Window Info program. Simply, drag the Finder Tool to the head of the calculator program window by pressing on the Finder Tool, then release the mouse on the head of the calculator program window as the following image explains.


After releasing the Finder Tool on the head of the calculator window program, return to the AutoIt Window Info program, to view the displayed information about the calculator program window. More importantly, go to the Summary tab at the end to the right as the following image explains.


In the Summary tab, you will find that it contains different sections, and each section provides information about a specific term.




The sections are:

  • &gt&gt&gt&gt Window &lt&lt&lt&lt: provides details about the targeted program window like: window title, window size and window position
  • &gt&gt&gt&gt Control &lt&lt&lt&lt: provides details about the targeted control (such as a button) in the targeted program window like: control class (e.g. Button, Edit), control ID in the targeted window and visible text in the control
  • &gt&gt&gt&gt Mouse &lt&lt&lt&lt: provides information about the mouse like: mouse position relative to the screen
  • &gt&gt&gt&gt StatusBar &lt&lt&lt&lt: provides information about window status bar like: text in the status bar
  • &gt&gt&gt&gt ToolsBar &lt&lt&lt&lt: provides information about window tools bar
  • &gt&gt&gt&gt Visible Text &lt&lt&lt&lt: provides all the visible text that could be extracted from the targeted program window
  • &gt&gt&gt&gt Hidden Text &lt&lt&lt&lt: provides all the the hidden text that could be extracted from the targeted program window


Well, we don't need all these information about program windows and controls because part of these information would be enough for us to help us writing AutoIt3 scripts. For understanding the value of AutoIt Window Info program, let me demonstrate the following example.

First, make sure that the following programs are running to start the work:

  • SciTE Script Editor (AutoIt3 script editor)
  • AutoIt Window Info
  • Calculator












We will use the AutoIt Window Tool to help us to automate addition process in the calculator program window. We will automate 5+10 process in the calculator program.

First thing is to save the script in your machine. Click on Save As (Ctrl+Shift+S) from File Menu, then save it.

Now, let's start the automation process. We want to complete the addition process in the calculator window. Let's analyze the steps to automate the process of 5+10

  1. Click on (5) button in calculator window
  2. Click on (+) button in calculator window
  3. Click on (1) button in calculator window
  4. Click on (0) button in calculator window
  5. Click on (=) button in calculator window


Let's move to AutoIt script editor to start the coding of our script. As I indicated above that the first step is to simulate button click on (5) button, but we need to get information about the (5) button in the calculator window. For establishing this, use the Finder Tool in AutoIt Window Info. Drag the Finder Tool and release it on the (5) button in the calculator window. Then the Summary tab will get updated as shown below. Note that the (5) button in the calculator window has ID: 129 that you can see it in the Control section, and we will use it in our script.


Let's return to AutoIt3 script editor. Now we have the information about the (5) button, and we want to simulate a click on it. For accomplishing this, we need to call ControlClick() function in AutoIt3. The first parameter is the title of the window that contains the control (the button). The second parameter is the text of the window (we don't need to send detailed text of the window since we have the control id, so we send ""). The third parameter is the ID of the control which is 129 in our case. So the function call will be like the following:
Note that the parameters like the title, text and control id can be copied from AutoIt Window Info, so you don't struggle with typo errors.

Next, we need to simulate a click on (+) button in the calculator window. We follow the same steps as we did above. First, drag the Finder Tool in AutoIt Window Info and release on (+) button in the calculator window. Then, get the ID of the control. Finally, call the ControlClick() function as the following. The ID of the (+) that I got is 92, so the function call will be like the following:
ControlClick("Calculator","",129)
ControlClick("Calculator","",92)

After that, do the same steps as we did above, but this time with (1) button in the calculator window. The ID of (1) button that I got is 125, so the function call is like the following:
ControlClick("Calculator","",129)
ControlClick("Calculator","",92)
ControlClick("Calculator","",125)

Again, do the same steps, but this time with (0) button in the calculator window. The ID of (0) button that I got is 124, so the function call is like the following:
ControlClick("Calculator","",129)
ControlClick("Calculator","",92)
ControlClick("Calculator","",125)
ControlClick("Calculator","",124)

Again, do the same steps, but this time with (=) button in the calculator window. The ID of (=) button that I got is 112, so the function call is like the following:
ControlClick("Calculator","",129)
ControlClick("Calculator","",92)
ControlClick("Calculator","",125)
ControlClick("Calculator","",124)
ControlClick("Calculator","",112)

By this, we finished from developing our script that automates (5+10) in the calculator window. Note that this script will give you the expected result only when the calculator program is running. Let's run the script to see if it works as expected. Run the script by pressing (F5), or click on Go command in Tools Menu.

Now, check the calculator window, and I'm sure you will see that the answer is 15. So we automated 5+10 in the calculator program.


If you want the script to run the calculator program, then automate the addition add the following two new statements in your script. The first script calls the Run() function that will run the calculator program. The second statement calls WinWaitActive() function that makes the script to wait for the calculator window to be active, so the script can start the addition process.

Run("calc")
WinWait("Calculator")
ControlClick("Calculator","",129)
ControlClick("Calculator","",92)
ControlClick("Calculator","",125)
ControlClick("Calculator","",124)
ControlClick("Calculator","",112)

Now, close the calculator window, then run the script by pressing (F5). the script will run the calculator program, then it will do (5+10).

In Conclusion, the main purpose of this tutorial was to help you understand the value of AutoIt Window Info program that was integrated with AutoIt3 Full Installation Package, and how it can be helpful in writing AutoIt3 scripts to automate certain tasks in programs windows.

I would like to see from you some reviews about my tutorials, so I can improve my future tutorials.

Take Care.

6 comments:

  1. Very nice and simple example.
    How do you use AutoIt3 to select an item on a drop-down menu?

    ReplyDelete
    Replies
    1. Welcome Tihamer. Sorry for the late answer. Sometimes you can solve problems by thinking in a different way. My knowledge in Autoit is limited because Autoit is full of functions that you utilize.

      Well, I don't recall a function that well select from drop down, but what I can suggest for you is to select item from drop down menu is that you can either use (mousemove) function to click on the drop down menu, then the menu will show up, then you can use (send) function to send (Down Arrow or Up Arrow) to reach the option that you need. Note that you have to know the order of the option that you are going to select in advance. I hope this works for you.

      Thank

      Delete
  2. Also, Autoit can work on c#. Visit here http://autoitsourcecode.blogspot.com/2013/04/how-to-use-autoit-in-c.html or http://autoitsourcecode.blogspot.com/2013/04/autoit-control-send.html

    ReplyDelete
  3. Thanks for the information, i am trying to perform the same with sql developer where i cannot find any details but mouse click and we are trying .ini file for script. What to do for the such cases where we cant find anything autoit win info but only mouse positions !!!

    ReplyDelete
    Replies
    1. Well, I'm not familiar with this sql developer you mentioned, but in case the autoit win-info doesn't work. The only option that remain for use is mouse clicks, and keyboard shortcuts. The Send() function comes in handy for sending keyboard shortcuts.

      Delete