At work, we use a Java based system and although I used AutoIt to automate keystrokes many times – and it works – however there are times where I found it difficult to tune my scripts to understand when it should wait for a special screen to pop up before it continues executing – AutoIt Window Info can’t help it.
Let’s take this example:
There’s a file with 300 records and I want AutoIt to read from the file and input the values in the respective fields on the system (I did this because the system uploader crashed many times).
I certainly was monitoring how the automation script worked and what are the unexpected results mostly due to the short $delay value I set which controls the wait time in ms between entering values into the system fields.
I also tried to set $delays variable to the maximum time I think is sufficient and won’t slow up my script too – and it fails at the rate of 1 record/15 records or just at 70/300 and repeats at other points because of unexpected lags! I wanted all records to be in the same order as in the input file.
So I thought of a own developed technique given the following:
- I know that the total execution time of the script is something that I can sit, relax and monitor and won’t waste much time of mine.
- No pop up windows will appear during the execution time (no interception and I’m also there in case I need to switch back to the system window manually).
- System special window which I want my script to wait for always in appears in the same position – in other words (x, y) pixel coordinates won’t change unless I do move the window and I won’t do it.
Because all of the above satisfies every time:
- I took a screenshot of the whole screen when the system special window appeared.
- I extracted a portion of the window’s title from the screenshot (serves as an identifier to the window), saved it as JPEG image and calculated it’s MD5 checksum value which will never change
- I noted the (x, y) pixel coordinates of the region I extracted in point #2
- I inserted a similar code of the one in this topic to my script to tweak it into waiting for that special window when it appears (basically takes a screenshot of the same size as in point #2 starting at the same (x, y) coordinates, saves it as JPEG, calculates the MD5 hash and compares it to the fixed known MD5 value from point #2
- The script will take screenshots every 250 ms which was ok and fast in my situation
Here’s the script that I used just to test if my technique worked and I used BMP format at that time:
$md5 = _Crypt_HashFile(@DesktopDir & "\checksum.bmp", $CALG_MD5)
$hBmp = _ScreenCapture_Capture("", 750, 325, 750+100, 325+100, False)
_ScreenCapture_SaveImage(@DesktopDir & "\GDIPlus_Image.bmp", $hBmp)
$checksum = _Crypt_HashFile(@DesktopDir & "\GDIPlus_Image.bmp", $CALG_MD5)
If $checksum = $md5 Then
* This is the BMP checksum image (a region of my Windows 7 background at the time of test at 1920×1080 resolution)
I hope this helps you or your friends. If you make and sell AutoIt programs then perhaps this could work for one of your clients.
All the best