Jump to content
Sign in to follow this  

Close Gui after a certain time of inactivity

Recommended Posts


I have a bit of a situation with my GUI, i need to automatically close the GUI after a period of inactivity lets say 15 minutes of not being used??

Is this possible?



Share this post

Link to post
Share on other sites


Here is a way of doing it, have a TimerInit() before the start of the windows msg loop, check for it reaching a idle maximum duration as one of the cases, after any other case reset the timmer. i made a little example that has two button that will reset the timmer and a status to show the idle time in seconds.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>


Func _Form1()
    #Region ### START Koda GUI section ### Form=
    Local $Form1 = GUICreate("Form1", 196, 94, -1, -1)
    Local $hButton1 = GUICtrlCreateButton("Button1", 20, 24, 75, 25)
    Local $hButton2 = GUICtrlCreateButton("Button2", 100, 24, 75, 25)
    Local $hStatusBar1 = _GUICtrlStatusBar_Create($Form1)
    _GUICtrlStatusBar_SetText($hStatusBar1, "Idle Time: ")
    #EndRegion ### END Koda GUI section ###
    Local $iTimmer = TimerInit()
    Local $iTimmerDuraction = 20000
    Local $sStatusText

    While 1
        $nMsg = GUIGetMsg()
            Case $nMsg = $GUI_EVENT_CLOSE
            Case $nMsg = $hButton1
                MsgBox(0, "Button1", "Idle timmer reset")
                $iTimmer = TimerInit()
            Case $nMsg = $hButton2
                MsgBox(0, "Button2", "Idle timmer reset")
                $iTimmer = TimerInit()
            Case TimerDiff($iTimmer) >= $iTimmerDuraction
                MsgBox(0, "Times up", "Idle time limit reached")
            Case Else
                Local $sNewTimeText = "Idle Time: " & Round(TimerDiff($iTimmer) / 1000)
                If $sStatusText <> $sNewTimeText Then
                    $sStatusText = $sNewTimeText
                    _GUICtrlStatusBar_SetText($hStatusBar1, $sStatusText)
EndFunc   ;==>_Form1

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...