Jump to content

Sleep with While 1 loop


hglaam
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

  • Moderators

hglaam,

Welcome to the AutoIt forums.


A not very elegant way to do it:

#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


 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

59 minutes ago, hglaam said:

Beautiful , thank you so much Melba23 :thumbsup:  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 

 

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...