140 likes | 223 Views
Debugging, Console Writing, PixelSearching. Week 5. Debugging Code. We’ve become familiar with Msgbox and TrayTip When would you want to use Msgbox ? When would you want to use TrayTip ?. ConsoleWrite – Look at SciTE.
E N D
Debugging Code • We’ve become familiar with Msgbox and TrayTip • When would you want to use Msgbox? • When would you want to use TrayTip?
ConsoleWrite – Look at SciTE ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") HotKeySet("{F1}","CloseWindow") While 1 Sleep(100) Wend Func Start() ConsoleWrite("data") EndFunc Func Quit() Exit EndFunc
Why would we want ConsoleWrite? What do you think?
ConsoleWrite • Modify Our Browser Program to ConsoleWrite when Notepad or FireFox Opens • Also, make each output separated by a carriage return. Look online how to find this (Hint: Use a domain search of autoitscript.com) • I’ve attached last weeks old code
;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") HotKeySet("{F1}","CloseWindow") While 1 Sleep(100) Wend Func Start() $val = inputbox("","Type in your Program") If $val == "notepad" Then run("notepad.exe") WinWaitActive("[Class:Notepad]") Send("Hello") ElseIf $val == "firefox" Then run("C:\Program Files\Mozilla Firefox\firefox.exe") WinWaitActive("[Class:MozillaUIWindowClass]") ControlClick("[Class:MozillaUIWindowClass]","","[CLASS:MozillaWindowClass; INSTANCE:1]","left",1,384, 35) sleep(10) ControlSend("[CLASS:MozillaUIWindowClass]", "","[CLASS:MozillaWindowClass; INSTANCE:1]" , "http://www.google.com{ENTER}") WinWaitActive("Google") Else Traytip("Wrong Input", $val, 10) Start() EndIf EndFunc Func Quit() Exit EndFunc FuncCloseWindow() If WinActive("[Class:Notepad]") Then WinClose("[Class:Notepad]") ElseIfWinActive("[Class:MozillaUIWindowClass]") Then WinClose("[Class:MozillaUIWindowClass]") EndIf EndFunc
Create your own Executable Program • Go to U:\MURT 102\install\Aut2Exe • Choose Your Source File .au3 • Choose a new name for your program • Double click it and run it. • Notice how the ConsoleWrite doesn’t appear
PixelSearching ; Find a pure red pixel in the range 0,0-20,300 $coord = PixelSearch( 0, 0, 230, 300, 0x0019B8 ) If Not @error Then MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1]) EndIf ; Find a pure red pixel or a red pixel within 10 shades variations of pure red $coord = PixelSearch( 0, 0, 20, 300, 0x0019B8, 10 ) If Not @error Then MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1]) EndIf
PixelSearch • Can you modify this so the coordinates are displayed with ConsoleWrite • Can you modify this so it moves the mouse to the PixelSearch Coordinate?
Food for Thought • Look Up Other Pixel Functions • How Might we use a pixel function to find text super fast?
Pixel Search Game • Make a program that plays Wacky Wack a Mole http://james.site90.net/upload/2011February17th129800505337flash.html
PixelSearch Game • Make it Search for a Brown Pixel (it is the same color as the Clickhere Banner) • Forget ControlClick, it is a bit buggy. Instead use it to create an offset. We’ll do the same effect • We don’t need to use a for-loop in PixelSearch • I’m Providing Skeleton Code • No Solution Until Next Week
Skeleton Code ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") While 1 Sleep(100) Wend Func Start() WinActivate("[Class:IEFrame]") $controlXOffset = 22 ;%Your Window Position Here $controlYOffset = 146 ;Your Window Position Here ConsoleWrite("X:= " & $controlXOffset & " Y:= " & $controlYOffset) ;ControlClick("[Class:IEFrame]","","[CLASS:MacromediaFlashPlayerActiveX; INSTANCE:1]","left",1,201, 173) ;Get through the Start Menu MouseClick("left", 201 + $controlXOffset, 173 + $controlYOffset, 1) Sleep(100) MouseClick("left", 232 + $controlXOffset, 254 + $controlYOffset, 1) Sleep(100) MouseClick("left", 225 + $controlXOffset, 230 + $controlYOffset, 1) for $i = 1 to 300 $coord = PixelSearch(…) If Not @error Then ConsoleWrite("X:= " & $coord[0] & " Y:= " & $coord[1] & @CRLF) EndIf next EndFunc ;==>Start Func Quit() Exit EndFunc ;==>Quit
Solution ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") While 1 Sleep(100) Wend Func Start() WinActivate("[Class:IEFrame]") $controlXOffset = 22 ;%Your Window Position Here $controlYOffset = 146 ;Your Window Position Here ConsoleWrite("X:= " & $controlXOffset & " Y:= " & $controlYOffset) ;ControlClick("[Class:IEFrame]","","[CLASS:MacromediaFlashPlayerActiveX; INSTANCE:1]","left",1,201, 173) ;Get through the Start Menu MouseClick("left", 201 + $controlXOffset, 173 + $controlYOffset, 1) Sleep(100) MouseClick("left", 232 + $controlXOffset, 254 + $controlYOffset, 1) Sleep(100) MouseClick("left", 225 + $controlXOffset, 230 + $controlYOffset, 1) for $i = 1 to 300 $coord = PixelSearch(9+$controlXOffset, 133 + $controlYOffset, 491+$controlXOffset, 336+$controlYOffset, 0x8D5801, 10, 20) If Not @error Then ConsoleWrite("X:= " & $coord[0] & " Y:= " & $coord[1] & @CRLF) MouseClick("left", $coord[0], $coord[1]) EndIf next ;0xFF0000 ;0x770000 EndFunc ;==>Start Func Quit() Exit EndFunc ;==>Quit