Jump to content

Recommended Posts

Posted

Hello,

I'm trying to design a GUI in AutoIT in which I could start and stop a while loop any time the specified Button is clicked.

I want to record the desktop activities when the start is clicked by the user and stop it when stop is clicked ans then start it again also whenever start is clicked.  

The problem is when I click the start , it could never be stopped. Is there an Idea? Thank you in advance

Here is my code:

#include <GUIConstantsEx.au3>

 $hGUI = GUICreate("D.A.Recorder", 250, 100)

 $hButton_1 = GUICtrlCreateButton("Start", 10, 10, 80, 30)
 $hButton_2 = GUICtrlCreateButton("Stop", 10, 50, 80, 30)

 GUISetState()

 While 1
     Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
             Exit
         Case $hButton_1 , $hButton_2
             _Func_1()
     EndSwitch
 WEnd

 Func _Func_1()
    While 1
      $IdMsg = GUIGetMsg()
      if $IdMsg = $hButton_2 Then
           ExitLoop
      EndIf

      Local $Wactive = WinGetTitle("[ACTIVE]")

      $Begin = TimerInit()
      $BeginTime = @HOUR & ":" & @MIN

      WinWaitNotActive($Wactive) ;Just waits until the current active Window is either closed or another window set as active
      $dif = TimerDiff($begin)   ;Calculates the elapsed time in Milliseconds

      $EndTime = @HOUR & ":" & @MIN
      $WorkedTime = $dif/1000     ;Convert the time to seconds

      $result = StringFormat("%.2f",$WorkedTime)
      FileWriteLine("OfflineRecorder.txt", $BeginTime & " | " & $EndTime & " | " & $result & "     | " & $Wactive)

   WEnd
 EndFunc
 

Posted

First of all, please use AutoIt code tags for your code.

About your issue, probably inside the loop it's hangs on WinWaitNotActive call and thus your button event not checked.

You could make a wrapper for that function to see if during it's execution there is some events from the GUI:

#include <GUIConstantsEx.au3>

Global $bStart = False

$hGUI = GUICreate("D.A.Recorder", 250, 100)
$iStart_Bttn = GUICtrlCreateButton("Start", 10, 10, 80, 30)
$iStop_Bttn = GUICtrlCreateButton("Stop", 10, 50, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iStart_Bttn
            $bStart = True
        Case $iStop_Bttn
            $bStart = False
    EndSwitch
    
    If $bStart Then
        $Wactive = WinGetTitle("[ACTIVE]")
        
        $Begin = TimerInit()
        $BeginTime = @HOUR & ":" & @MIN
        
        ;---- WinWaitNotActive Wrapper ----
        ;Just waits until the current active Window is either closed or another window set as active
        While WinActive($Wactive)
            Switch GUIGetMsg()
                Case $iStop_Bttn
                    $bStart = False
                    ExitLoop
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        WEnd
        ;---- WinWaitNotActive Wrapper ----
        
        If $bStart Then
            $dif = TimerDiff($begin) ;Calculates the elapsed time in Milliseconds
            
            $EndTime = @HOUR & ":" & @MIN
            $WorkedTime = $dif / 1000 ;Convert the time to seconds
            
            $result = StringFormat("%.2f", $WorkedTime)
            FileWriteLine("OfflineRecorder.txt", $BeginTime & " | " & $EndTime & " | " & $result & "     | " & $Wactive)
        EndIf
    EndIf
WEnd

 

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

Your welcome.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
  • Recently Browsing   0 members

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