nonorai Posted August 9, 2013 Share Posted August 9, 2013 (edited) Hi helper, I've created a program that send key 9 to a window after some secs (which user select). Everything is create but only for the 1st time (the loop does not work). Can anyone help me to look into the problem many thanks for help expandcollapse popup#include <Date.au3> #include <GUIConstantsEx.au3> Global $Start, $Stop, $Exit, $msg, $Time, $TimeOP, $Flag Global $Timer, $Secs, $Mins, $Hour, $Timer1 GUICreate("Custom Msgbox", 210, 80) GUICtrlCreateLabel("Thoi gian hoi (s)", 10, 10) $Time = GUICtrlCreateInput ("s", 90, 7, 30, 20) $Start = GUICtrlCreateButton("Start", 10, 50, 50, 20) $Stop = GUICtrlCreateButton("Stop", 80, 50, 50, 20) $Exit = GUICtrlCreateButton("Exit", 150, 50, 50, 20) GUISetState() ; display the GUI $Timer = TimerInit() AdlibRegister("Timer", 50) While 1 $msg = GUIGetMsg() Select Case $msg = $Start $TimeOP = GUICtrlRead($Time) Action () Case $msg = $Exit MsgBox(0, "Thoat", "Bye") Exit Case $msg = $GUI_EVENT_CLOSE MsgBox(0, "You clicked on", "Close") Exit EndSelect WEnd Func Timer() _TicksToTime(Int(TimerDiff($Timer)), $Hour, $Mins, $Secs) If $Mins < 0 Then $Timer1 = $Mins Else $Timer1 = $Mins * 60 + $Secs EndIf EndFunc ;==>Timer Func Action() GUICtrlSetState($Time, $GUI_DISABLE) While 1 If $Timer1 = $TimeOP Then ToolTip($Timer1, 0, 0) Send("9") $Timer1 = 0 EndIf If $msg = $Stop Then GUICtrlSetState($Time, $GUI_ENABLE) ExitLoop EndIf WEnd EndFunc Edited August 9, 2013 by nonorai Link to comment Share on other sites More sharing options...
FireFox Posted August 9, 2013 Share Posted August 9, 2013 (edited) Hi,Welcome to the autoit forum AutoIt is a single threaded language, you can not run two (or more) While at the same moment.Hence in your sub While the $msg var won't be updated (same thing for the $Timer1 var). The trick is to put everything in the main loop with a condition :expandcollapse popup#include <Date.au3> #include <GUIConstantsEx.au3> Global $_fAction = False Local $iBtnStart = 0, $iBtnStop = 0, $iBtnExit = 0, $iMsg = 0, $sTimeOP = "" Global $hTimer = 0, $_iTimer1 = 0, $_iInputTime = 0 GUICreate("Custom Msgbox", 210, 80) GUICtrlCreateLabel("Thoi gian hoi (s)", 10, 10) $_iInputTime = GUICtrlCreateInput("s", 90, 7, 30, 20) $iBtnStart = GUICtrlCreateButton("Start", 10, 50, 50, 20) $iBtnStop = GUICtrlCreateButton("Stop", 80, 50, 50, 20) $iBtnExit = GUICtrlCreateButton("Exit", 150, 50, 50, 20) GUISetState() ; display the GUI $hTimer = TimerInit() AdlibRegister("Timer", 50) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $iBtnStart $sTimeOP = GUICtrlRead($_iInputTime) Action() Case $iBtnExit MsgBox(0, "Thoat", "Bye") ExitLoop ;also exits the script Case $GUI_EVENT_CLOSE MsgBox(0, "You clicked on", "Close") ExitLoop EndSwitch If $_fAction Then If $_iTimer1 = Number($sTimeOP) Then ToolTip($_iTimer1, 0, 0) Send("9") $_iTimer1 = 0 EndIf If $iMsg = $iBtnStop Then GUICtrlSetState($_iInputTime, $GUI_ENABLE) ExitLoop EndIf EndIf WEnd GUIDelete() Func Timer() Local $iHour = 0, $iMin = 0, $iSec = 0 _TicksToTime(Int(TimerDiff($hTimer)), $iHour, $iMin, $iSec) If $iMin < 0 Then $_iTimer1 = $iMin Else $_iTimer1 = $iMin * 60 + $iSec EndIf EndFunc ;==>Timer Func Action() GUICtrlSetState($_iInputTime, $GUI_DISABLE) $_fAction = True EndFunc ;==>ActionBr, FireFox. Edited August 9, 2013 by FireFox Link to comment Share on other sites More sharing options...
nonorai Posted August 9, 2013 Author Share Posted August 9, 2013 WoW thanks alot for your help [my idol] Link to comment Share on other sites More sharing options...
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