AutoIt Notepad

Aus ExpeccoWiki

Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

Description

With AutoIt you can interact with all standard Windows GUIs. This example demonstrates how to open the notepad.exe application, then to type-in some text, and finally to close the window afterwards. At that point it has to interact with the applcations save-dialog.

Opening the Notepad

In order to open the notepad we have to execute 'notepad.exe'. This is done by the "AutoIt [ Run ]" block. It is given the file name of the executable. The alternative "AutoIt [ RunAs ]" block adds a possibility to specify a user and a domain to execute the program. After the task is started, we must wait for the window to become active. The "AutoIt [ WinWaitActive ]" block pauses 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 "Untitled - Notepad" with English settings and "Unbenannt - Editor" with German ones.

AutoIt Example Notepad Open Wait.png

Setting the "Typing Speed"

When simulating e.g. keystrokes you can modify the simulation speed. Here we will use the "AutoIt [ SetOpt ]" block to set the option "SendKeyDelay" to the value 100 [milliseconds]. That way we can keep track of the typing.

AutoIt Example Notepad Setting.png

Typing Text and Exiting

Now we can type some sample text into the notepad using the "AutoIt [ Send ]" block to send simulated keystrokes. Please note that the send mode is set to 1. This mode is used to send raw key data. After we have finished typing we also send "!f" ('ALT + F[ile]') to open the file menu via shortcut (On German settings this would be equal to "!d" for 'ALT + D[atei]'). This time we use the send mode 0. Then we select the menu entry 'Exit' by sending "x" (German: 'Beenden' -> "b").

AutoIt Example Notepad Type Exit.png

Interacting with the Save Dialogue

Finally we have to wait again for the save dialogue to become active. It is titled "Editor" in English and "Notepad" in German. By sending the shortcut "n" for 'No' we close the notepad without saving.

AutoIt Example Notepad Save Dialog.png


Back to Examples.

Meine Werkzeuge