hglaam Posted September 28, 2017 Posted September 28, 2017 I need help with this problem, i have an infinite loop with while 1 loop and i want to put a sleep ( as long as we inputted ) and when we hit the button , the loop will end ; but i can't , please help My current codes While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $inp1 = GUICtrlRead($Input1) $inp2 = GUICtrlRead($Input2) _GUICtrlListView_AddItem($ListView1,$inp1) While 1 WinActivate('thu - Notepad') Send("{ENTER}") Send($inp1) Send("{ENTER}") for $i =0 to 1 Sleep($inp2) ExitLoop Next If GUIGetMsg() = $Button3 Then ExitLoop WEnd Case $Button2 MsgBox(0,"Thoát","Bạn chắc bắn muốn thoát Auto chat chứ ?") Exit EndSwitch WEnd
Moderators Melba23 Posted September 28, 2017 Moderators Posted September 28, 2017 hglaam, Welcome to the AutoIt forums. A not very elegant way to do it: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $Input1 = GUICtrlCreateInput("", 10, 10, 200, 20) $Input2 = GUICtrlCreateInput("", 10, 50, 200, 20) $Button1 = GUICtrlCreateButton("Go", 10, 100, 80, 30) $Button2 = GUICtrlCreateButton("Exit", 110, 100, 80, 30) $Button3 = GUICtrlCreateButton("Stop loop", 210, 100, 80, 30) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $inp1 = GUICtrlRead($Input1) $inp2 = GUICtrlRead($Input2) ;_GUICtrlListView_AddItem($ListView1,$inp1) $nBegin = TimerInit() ; Get a timestamp While 1 ;WinActivate('thu - Notepad') ;Send("{ENTER}") ;Send($inp1) ;Send("{ENTER}") $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button3 ConsoleWrite("Exiting loop on button" & @CRLF) ExitLoop EndSwitch ; Check time since loop started If TimerDiff($nBegin) > $inp2 Then ConsoleWrite("Exiting loop on timer" & @CRLF) ExitLoop EndIf WEnd Case $Button2 If MsgBox($MB_YESNO, "Thoát", "B?n ch?c b?n mu?n thoát Auto chat ch? ?") = 6 Then ; Why not ask? Exit EndIf EndSwitch WEnd To see a more elegant method, take a look at the Interrupting a running function tutorial in the Wiki. Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
hglaam Posted September 29, 2017 Author Posted September 29, 2017 Beautiful , thank you so much Melba23
hglaam Posted September 29, 2017 Author Posted September 29, 2017 59 minutes ago, hglaam said: Beautiful , thank you so much Melba23 But i still have a question i want to send key and characters even when the window( Notepad or anything ) is minimize or inactive, i've tried controlsend but not working, it only send when the window is active
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now