1 / 16

Week4

Week4. If Statements. Things I’ve Used AutoIt for recently. I created a Mute Button for my PC using HotKeys . Now I can control the volume from my keyboard I created this code for drawing randomly in panit . Something Fun – Open Paint . HotKeySet ("{ESC}", "Quit")

jennis
Download Presentation

Week4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week4 If Statements

  2. Things I’ve Used AutoIt for recently • I created a Mute Button for my PC using HotKeys. Now I can control the volume from my keyboard • I created this code for drawing randomly in panit.

  3. Something Fun – Open Paint HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "MoveMouse") for $i = 0 to 500 TrayTip("", $i, 1) sleep(10) Next FuncMoveMouse() for $i = 0 to 1000 MouseClickDrag("left",random(0,500)+200,random(0,500)+200,random(0,500)+200,random(0,500)+200,0) next EndFunc Func Quit() Exit EndFunc

  4. Email Me • Email me for attendance. • Let me know how this class is going for you. Too fast, too slow. • Do you want homework assignments, small ones? Would this help you? • What can I do to help you?

  5. New Skeleton for future Programs HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") While 1 Sleep(100) Wend Func Start() ;MainCode EndFunc Func Quit() Exit EndFunc

  6. Goal of this Class • Let’s make a program that let’s us access our favorite programs quickly

  7. If-Statements • Remember If-Statements? • http://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm • Remember == is not the same as = If ($parameter…) Then … EndIf

  8. ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") While 1 Sleep(100) Wend Func Start() $val = inputbox("","Type in the #Notepad") If $val == 1 OR $val == 2 Then run("notepad.exe") EndIf EndFunc Func Quit() Exit EndFunc

  9. Let’s modify this to have two programs open: • If someone types “notepad”, Notepad opens. • If someone types “firefox”, Firefox opens • Otherwise repeat the function • To runFirefox, you must locate the exact location of the executable (.exe) file. run("C:\Program Files\Mozilla Firefox\firefox.exe") • To call a function again just type it Start()

  10. Solution to Previous Exercise ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") While 1 Sleep(100) Wend Func Start() $val = inputbox("","Type in your Program") If $val == "notepad" Then run("notepad.exe") ElseIf $val == "firefox" Then run("C:\Program Files\Mozilla Firefox\firefox.exe") Else Traytip("Wrong Input", $val, 10) Start() EndIf EndFunc Func Quit() Exit EndFunc

  11. Closing Programs • Let’s make a hotkey “{F1}” that closes NotePad or Firefox if it exits • Check if the Window Exists with WinActive • Close a Window with WinClose • Find the Class/Title of the program with • Title is the title of the program’s window • Class is the type of program’s window

  12. Solution to the Previous Problem ;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") ElseIf $val == "firefox" Then run("C:\Program Files\Mozilla Firefox\firefox.exe") 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

  13. WinWaitActive • Let’s Send Text • Now, instead of the sleep command, we can wait for a window to activate with WinWaitActive • Send Text to Notepad waiting for it to Activate

  14. ;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") 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

  15. Controls • Controls are a way to simulate a click or keyboard without actual movements. It sends it directly to the Window without pretending there is an external hardware connected. • Look at ControlClick and ControlSend • Use this to navigate to Google • You may need to delay slightly between ControlClick and ControlSend

  16. Solution to Previous 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

More Related