• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; This is a sample AutoIt script, based on the notepad1 sample script by Jonathan Bennett.
2; It runs notepad, enters some text and exits.
3
4
5; Exit with a nonzero exit status if the parameter equals 0.
6; This is useful for functions that return 0 upon failure.
7Func Assert($n)
8    If $n = 0 Then Exit(1)
9EndFunc
10
11; Wait for a window to exist, activate it, and wait for it to become active.
12; If timeout expires while waiting, exit with a nonzero exit status.
13Func WaitForWindow($title, $text="", $timeout=60)
14    Assert(WinWait($title, $text, $timeout))
15    WinActivate($title, $text)
16    Assert(WinWaitActive($title, $text, $timeout))
17EndFunc
18
19; Run Notepad
20Assert(Run("notepad.exe"))
21
22; Wait up to 10 seconds for Notepad to become active --
23; it is titled "Untitled - Notepad" on English systems
24WaitForWindow("Untitled - Notepad", "", 10)
25
26; Now that the Notepad window is active type some text
27Send("Hello from Notepad.{ENTER}1 2 3 4 5 6 7 8 9 10{ENTER}")
28Sleep(500)
29Send("+{UP 2}")
30Sleep(500)
31
32; Now quit by pressing Alt-f and then x (File menu -> Exit)
33Send("!f")
34Send("x")
35
36; Now a screen will pop up and ask to save the changes, the window is called
37; "Notepad" and has some text "Yes" and "No"
38WaitForWindow("Notepad", "", 10)
39Send("n")
40
41; Now wait for Notepad to close before continuing
42WinWaitClose("Untitled - Notepad", "", 10)
43
44; Finished!
45