How to compile the autohotkey script

Source: Internet
Author: User
Tags blank page

The previous article introduced the basic functions and general modules of autohotkey. This time, we will use a simple example to illustrate how to compile autohotkey scripts. Like popular automated testing tools, you can write scripts by recording them, or manually writing scripts. However, for GUI applications, recording operations are basically required to generate scripts for objects or coordinates that have traveled. Autohotkey is relatively simple, basically only records coordinates. A few window operations are represented by objects, which is equivalent to low-level recording in popular automated testing tools.

The following is how to use autoscriptwriter (recorder) recording in autohotkey to open the IE browser in the "quick launch" column on the desktop, enter www.google.com in the address bar, and press Enter, enter test in Google search and press Enter.

---------

Winwait ,,
Ifwinnotactive, winactivate ,,
Winwaitactive ,,
Mouseclick, left, 125, 22
Sleep 100
Winwait, blank page-Windows Internet Explorer,
Ifwinnotactive, blank page-Windows Internet Explorer, winactivate, blank page-Windows Internet Explorer,
Winwaitactive, blank page-Windows Internet Explorer,
Send, www.google.com {enter}
Winwait, Google-Windows Internet Explorer,
Ifwinnotactive, Google-Windows Internet Explorer, winactivate, Google-Windows Internet Explorer,
Winwaitactive, Google-Windows Internet Explorer,
Send, test {enter}
Winwait, test-Google search-Windows Internet Explorer,
Ifwinnotactive, test-Google search-Windows Internet Explorer, winactivate, test-Google search-Windows Internet Explorer,
Winwaitactive, test-Google search-Windows Internet Explorer,
Mouseclick, left, 1016, 13
Sleep 100

--------------

You can see that the input is represented by "send" and "<character>". Click "mouseclick", "Left", "<X >,< y>. Many ifwinnotactive statements are similar to the synchronization statements in the test tool. Because coordinates often change, if you can use keys, try to use keys to avoid coordinates. You can click the "Google Search" button to implement the above "enter", but it is better to use the "enter" key for the sake of insurance.

Autohotkey also provides a better scripting language, which is similar to VBScript. You can open autohotkey help file to search for it. After a simple modification, the script is as follows:

--------------

Run % a_programfiles %/Internet Explorer/iexplore.exe; start IE browser
Sleep 5000; wait launch IE browser
Send, www.google.com {enter}; input Google's website in Address Bar
Sleep 5000; wait open Google's home page
Send, test {enter}; input keyword in search field
Sleep 5000; wait search result
Mouseclick, left, 1016, 13; click X button to close ie window

--------------

In the above script, I used sleep for synchronization. In fact, there are many other methods. For example, the waitobject statement is to execute the next operation when the color of a certain area or point is the expected color, you can also wait for an image. Because objects are not provided, other methods are not too flexible and need to be used in many places, so they are not used. You can use the following method for some important items:

Loop, 5
{
Ifwinexist, save as; check whether Save As dialogbox exists
Break
Else
Sleep % shortsleeptime %
}

You can also use winclose and A to close the window of the current activity. There are many such statements. Just like writing code before, the only one is that no other scripts can be called and only valid in the current script. However, I was not using it right away.

If you are interested, you can discuss it together.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.