Search code examples
user-interfaceautoitpause

AUTOIT GUI Management Pause Script when in Background


Hi all im currently writing a script to more easily manage (kill/delete) broken WTS Profiles. So in an attempt to make it easier for our support guys i came up with an autoit script to manage that.

I've got everything running smoothly except that my script is listening in on the "Enter" Key and if this is pressed he calls functions an so on. But he also does this when my script is running in the background and the user wants to google something or anything, he always registers the Enter Key.

So my Question now, how can i fix this because if it is a complex search (with asterisk and so on) it generats unneceserry I/O on the netshares where the Profiles are stored.

The Code in Question:

    While 1
        $nMsg = GUIGetMsg() 
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $SearchButton 
                $sSearchString = GUICtrlRead($SubmitField) & "*" 
                If $sSearchString = "*" Then ;
                    _OutputConsole_Updater()
                    GUICtrlSetData($ConsoleOutput, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] -" & " Keine Eingabe getätigt, bitte Suchbegriff eingeben")
                Else
                    _ReloadBox()
                    _SearchAll()
                EndIf
            Case $DeleteButton
                _DeleteSelection()
            Case $DeleteAll
                    _DeleteAllCheck()           
            Case $nMsg = _IsPressed("0D")
                $sSearchString = GUICtrlRead($SubmitField) & "*" ;
                If $sSearchString = "*" Then ;
                    _OutputConsole_Updater()
                    GUICtrlSetData($ConsoleOutput, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] -" & " Keine Eingabe getätigt, bitte Suchbegriff eingeben")
                Else
                    _ReloadBox()
                    _SearchAll()
                EndIf
        EndSwitch
WEnd

Solution

  • Do you operate with HotkeySet? Then activate the function only when your script is active

            If WinActive($scriptTitle) = 0 Then
                _setHotKeys()
            Endif
    
    Func _setHotKeys($state = 1)
        If $state = 1 Then
            HotKeySet('!1')
            HotKeySet('!2')
            HotKeySet('!3')
            HotKeySet('!4')
            HotKeySet('!5')
            HotKeySet('!6')
            HotKeySet('!7')
            HotKeySet('!8')
        ElseIf $state = 0 Then
            HotKeySet('!1', '_setTab0')
            HotKeySet('!2', '_setTab1')
            HotKeySet('!3', '_setTab2')
            HotKeySet('!4', '_setTab3')
            HotKeySet('!5', '_setTab4')
            HotKeySet('!6', '_setTab5')
            HotKeySet('!7', '_setTab6')
            HotKeySet('!8', '_setTab7')
        EndIf
    EndFunc   ;==>_setHotKeys