150 likes | 322 Views
Week3. Functions and HotKeys. Finish Old Code from Before. Your Turn. Make a program that clicks on the start menu Clicks on “All Programs” if it is there Scrolls upwards all the way to the top Clicks on a web browser Sends the tag http://www.google.com/finance?q=ntdoy
E N D
Week3 Functions and HotKeys
Your Turn • Make a program that clicks on the start menu • Clicks on “All Programs” if it is there • Scrolls upwards all the way to the top • Clicks on a web browser • Sends the tag http://www.google.com/finance?q=ntdoy • Drags over and copies the stock price • Displays the data in a Msgbox
Hints http://www.autoitscript.com/autoit3/docs/functions.htm • MouseClick • MouseClickDrag • MouseMove • MouseWheel • ClipGet/ClipPut • Send • Sleep • Msgbox
Functions • A function is like y(t) = 5*t • In AutoIt we used the word “Func”
Example Code $x = 1 $y = 2 $z1 = $x + $y $z2 = Add($x,$y) Msgbox(0,$z1, $z2) FuncAdd($a,$b) return $a + $b EndFunc
HotKeys, Grab By Function Name HotKeySet("{ESC}", “Quit") for $i = 0 to 1000 TrayTip("", $i, 1) sleep(100) Next Func Quit() Exit EndFunc
Let’s Delay a Program from running • Take your main code an put it in a function • Don’t let that code run until a Key is Pressed
HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "MoveMouse") for $i = 0 to 1000 TrayTip("", $i, 1) sleep(100) Next FuncMoveMouse() $end = 500 For $x = 0 to $end/2 step 100 $y = $end - $x MouseMove($x,$x, 2) MouseMove($y, $x, 2) MouseMove($y, $y, 2) MouseMove($x,$y, 2) Next EndFunc Func Quit() Exit EndFunc
Primary Method for Logic • Operators: Think of it like Math Logic • http://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm • Primary Methods: • If Statements • While Loops
While Loops –Less Than Func Start() $count = 1 while $count < 3 Msgbox(0,"", $count) $count+=1 WEnd EndFunc
While Loops –Less Than or Equal Func Start() $count = 1 while $count <= 3 Msgbox(0,"", $count) $count+=1 WEnd EndFunc
While Loop – Equals Statement Func Start() $count = 1 while $count < 4 while $count == 2 Msgbox(0,"", $count) WEnd $count+=1 WEnd EndFunc
If Statement • Like a While –Loop, but occurs only once. Meaning, no loop. Func Start() $count = 1 while $count < 4 If $count == 1 Then Msgbox(0,"", "a") ElseIf $count == 2 Then MsgBox(0,"", "b") Else Msgbox(0,"", "nothing") endif $count+=1 WEnd EndFunc