sELecTED 0 Posted May 30, 2010 Sleep("2400") Send ("2") Sleep ("1700") Send ("3") Sleep ("1700") Send ("4") Sleep("1700") Send ("5") Sleep("2400") Send ("5") Sleep("2400") Send ("5") This is my code. I want to start executing this loop when hotkey is pressed, and when pressed again to take the sequence from the beginning . can someone help me ? i must tell that im new to autoit and i think its nice Share this post Link to post Share on other sites
water 2,393 Posted May 30, 2010 Please have a look at "HotKeySet" in the help file. There you'll find a good example. I understand that you can't interrupt a "blocking" function (like Sleep). What do you want do do if the sequence is still running (due to the long sleep delays) and you hit the HotKey again? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
sELecTED 0 Posted May 30, 2010 ; Press Esc to terminate script, Pause/Break to "pause" Global $Paused HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d ;;;; Body of program would go here ;;;; While 1 Sleep(100) WEnd ;;;;;;;; Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',0,0) WEnd ToolTip("") EndFunc Func Terminate() Exit 0 EndFunc Func ShowMessage() MsgBox(4096,"","This is a message.") EndFunc I dont understand how it could help me... like I told earlier im pretty noob Share this post Link to post Share on other sites
water 2,393 Posted May 30, 2010 (edited) Please try this script. Alt+Shift+d starts your function, ESC exits the script . HotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "YourFunction") ;Shift-Alt-d While 1 Sleep(100) WEnd Func Terminate() ConsoleWrite("Exit" & @CRLF) Exit 0 EndFunc Func YourFunction() ConsoleWrite('Starting "YourFunction"' & @CRLF) Sleep("2400") Consolewrite ("2" & @CRLF) Sleep ("1700") Consolewrite ("3" & @CRLF) Sleep ("1700") Consolewrite ("4" & @CRLF) Sleep("1700") Consolewrite ("5 - First time" & @CRLF) Sleep("2400") Consolewrite ("5 - Second time" & @CRLF) Sleep("2400") Consolewrite ("5 - Third time" & @CRLF) ConsoleWrite('Finished "YourFunction"' & @CRLF) EndFunc Edited May 30, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
Tvern 11 Posted May 30, 2010 For a very basic understanding of hotkeys, functions and loops I've commented and simplified the example you posted: HotKeySet("{ESC}", "Terminate") ;this binds the function "Terminate" to the key "ESC" ;what key do you want to use, and what name do you want to give your function? While 1 ;This is the start of a loop. everything in here is repeated all the time Sleep(100) ;this is the content of the loop; the script just sleeps (waits) 100ms WEnd ;This is the end of the loop. ;do you want your script to do anything when you don't press a hotkey? Func Terminate() ;This is the start of function "Terminate" that is only executed when "ESC" is pressed Exit 0 ;This is what the function does; it exits the script EndFunc ;This is the end of function "Terminate" ;what do you want your function to do? Share this post Link to post Share on other sites
sELecTED 0 Posted May 30, 2010 Thank you both of you. Water I modified the script you gave to me and i pretty made it work perfectly for what i need. But now i want to do more: I want to create a simple GUI where i can insert a variable and then use the variable in the script. expandcollapse popupHotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "Rotation") ;Shift-Alt-d While 1 Sleep(100) WEnd Func Terminate() ConsoleWrite("Exit" & @CRLF) Exit 0 EndFunc Func Rotation() $i = 0 Do Sleep("2400") Send("2") Sleep ("1700") Send("3") Sleep ("1700") Send("4") Sleep("1700") Send("5") Sleep("2400") Send("5") Sleep("2400") Send("5") $i = $i + 1 Until $i = 10 EndFunc I want to insert the variable after the "Until $i =" so my script could be repeated how many times I want. I'm testing and try to do this on my own. This script is usable in WOW (world of warcraft) and its very useful. I'll come back with update. Thank you guys! Share this post Link to post Share on other sites
sELecTED 0 Posted May 30, 2010 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Sagittaz Hunter AutoRotation v1.1", 120,50) GUISetState(@SW_SHOW) GUICtrlCreateLabel ("Numar Repetari", 16,2) GUICtrlCreateInput ("", 16,20, 80,20, 0x2000) $repeats = GuiCtrlRead HotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "Rotation") ;Shift-Alt-d While 1 Sleep(100) WEnd Func Terminate() ConsoleWrite("Exit" & @CRLF) Exit 0 EndFunc Func Rotation() $i = 0 Do Sleep("2400") Send("2") Sleep ("1700") Send("3") Sleep ("1700") Send("4") Sleep("1700") Send("5") Sleep("2400") Send("5") Sleep("2400") Send("5") $i = $i + 1 Until $i = $repeats EndFunc How shall i use the GuiCtrlRead to get the value inserted in the input? Share this post Link to post Share on other sites
Tvern 11 Posted May 30, 2010 (edited) That's starting to look an awfull lot like a game bot.Please read this.edit:The moderators probably won't be too bothered by this thread, so it'll just die of old age. Don't give up on autoit though. I learned the basics for a game bot and had allot of legitimate uses for the knowledge since. Edited May 30, 2010 by Tvern Share this post Link to post Share on other sites
sELecTED 0 Posted May 30, 2010 oh, sry... im sorry didnt saw... waiting for moderation Share this post Link to post Share on other sites