Masum

Exit / Stop Script

12 posts in this topic

Hi all,

Ctrl+Break stops script only if AutoIt window is active. It doesn't work while automation is going on elsewhere.

Is there a way to stop the script regardless of where the automation is happening?

Thanks

Share this post


Link to post
Share on other sites



Thanks but that too didn't work, only worked while AutoIt was the active screen.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What didn't  work exactly as I have no idea what you mean with AutoIt being the active screen?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

As in when the script is automating other apps, like Excel and a remote application, exiting the script via CTRL+Break or via a HotKeySet does not work. Could this be due to the fact the script is always doing something, hence doesn't give it the chance to read any keyboard entry via a manual method, and hence why CTRL+Break or HotKeySet are not read to be actioned?

Share this post


Link to post
Share on other sites

Also, does this forum support email notification for post responses? I don't get any, hence the late replies...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Call me slow, but I am still puzzled what you mean here. Show me a demo script that has something blocking an hotkey set by HotKeySet().

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Hi, it's a fairly short script, hence I've copied all of it below. Two issues with it, 1. HotKey does not respond while the script is running, 2. the If conditions do not work, I've created a post for the second issue here

#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>

;Ensure this script is saved in the same directory as the DCW.
;Ensure InboxConfigTool.exe is open and Maximised.
;Ensure the screen resolution is set to 1366 x 768 and no additional screens are connected.

HotKeySet('e', 'EndProgram')

SelectManagePoolsTab()

;Create Excel application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

;Open DCW
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\CHB Data Collection Workbook - Message Centre.xls")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Error", "Error opening workbook '" & @ScriptDir & "CHB Data Collection Workbook - Message Centre.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf

$oExcel.Sheets("CHFT Pools & RTE Rules").Select ;Select the CHFT Pools & RTE Rules tab of the DCW

Local $Row = 13 ;Used to store data from cells of the current row, here the starting row is defined, 13 being the first row
Local $Finish = 'Finish' ;Used as an anchor to stop the script passed the last row of the DCW

Do
    Local $Status = _Excel_RangeRead($oWorkbook, 'CHFT Pools & RTE Rules', 'I' & $Row) ;Stores current data from the 'Built?' column
    MsgBox(0, "Status", "Status of cell I" & $Row & " is " & $Status)

    If $Status = '' Then
        Local $PoolName = _Excel_RangeRead($oWorkbook, 'CHFT Pools & RTE Rules', 'E' & $Row)
        Local $PoolDescription = _Excel_RangeRead($oWorkbook, 'CHFT Pools & RTE Rules', 'F' & $Row)
        Local $RTERuleName = _Excel_RangeRead($oWorkbook, 'CHFT Pools & RTE Rules', 'G' & $Row)
        Local $FirstName = _Excel_RangeRead($oWorkbook, 'CHFT Pools & RTE Rules', 'B' & $Row)
        Local $LastName = _Excel_RangeRead($oWorkbook, 'CHFT Pools & RTE Rules', 'A' & $Row)
        Local $Notes = _Excel_RangeRead($oWorkbook, 'CHFT Pools & RTE Rules', 'J' & $Row)
        Sleep(100)
        ActivateInboxConfigTool()
        AddPool()
        DragScrollBarUp()
        EnterPoolName()
        EnterPoolDescription()
        SearchForMember()
        AddMember()
        MakeTeamLead()
        SetMemberOptions()
        DragScrollBarDown()
        SetOrganisations()
        AddRTERule()
    EndIf

    $Row = $Row + 1
Until $Status = $Finish

Sleep(500)
MsgBox(64, 'Update', 'The script has finished building the pools from the chosen DCW, please review what needs to be redone or failed.')
Exit

Func ActivateInboxConfigTool()
    Do
        WinActivate("Inbox Config Tool")
        Sleep(100)
    Until WinActive("Inbox Config Tool")
EndFunc   ;==>ActivateInboxConfigTool

Func SelectManagePoolsTab()
    ActivateInboxConfigTool()
    Sleep(100)
    MouseClick('primary', 230, 118, 1) ;Click on Manage Pools tab
    Sleep(200)
EndFunc   ;==>SelectManagePoolsTab

Func AddPool()
    MouseClick("left", 554, 675, 1) ;Click Add
    Sleep(100)
EndFunc   ;==>AddPool

Func DragScrollBarUp()
    MouseClickDrag('Primary', 1345, 574, 1345, 401)
    Sleep(100)
EndFunc   ;==>DragScrollBarUp

Func EnterPoolName()
    MouseClick('Primary', 100, 409, 1) ;Click in Name field
    Sleep(100)
    Send($PoolName)
    Sleep(100)
EndFunc   ;==>EnterPoolName

Func EnterPoolDescription()
    MouseClick('Primary', 100, 458, 1) ;Click in Description field
    Sleep(100)
    Send($PoolDescription)
    Sleep(100)
EndFunc   ;==>EnterPoolDescription

Func SearchForMember()
    MouseClick('Primary', 100, 507, 1) ;Click in Search for Member field
    Sleep(100)
    Send('System,System')
    Sleep(100)
    Send('{TAB}') ;Tab over to the Magnifying glass button
    Send('{SPACE}') ;Press Magnifying glass
    Send('{Enter}') ;Press OK on the Clinical Staff Selection window
    Sleep(100)
EndFunc   ;==>SearchForMember

Func AddMember()
    MouseClick('Primary', 100, 612, 1) ;Select available member
    Sleep(100)
    MouseClick('Primary', 339, 619, 1) ;Click Add
    Sleep(100)
EndFunc   ;==>AddMember

Func MakeTeamLead()
    MouseClick('Primary', 411, 612, 1) ;Select active member
    Sleep(100)
    MouseClick('Primary', 499, 553, 1) ;Click Make Team Lead
    Sleep(100)
EndFunc   ;==>MakeTeamLead

Func SetMemberOptions()
    MouseClick('Primary', 689, 441, 1) ;Tick Allow users to opt-in or opt-out of membership
    Sleep(100)
    MouseClick('Primary', 689, 466, 1) ;Tick Allow users without org association to view the pool
    Sleep(100)
    MouseClick('Primary', 689, 492, 1) ;Tick Allow users without org association to forward to the pool
    Sleep(100)
EndFunc   ;==>SetMemberOptions

Func DragScrollBarDown()
    MouseClickDrag('Primary', 1345, 401, 1345, 574)
    Sleep(100)
EndFunc   ;==>DragScrollBarDown

Func SetOrganisations()
    Send('{CTRLDOWN}')
    MouseClick('Primary', 703, 576, 1) ;Select Bradford Royal Infirmary
    Sleep(100)
    MouseClick('Primary', 703, 619, 1) ;Selct Calderdale Royal Hospital
    Sleep(100)
    MouseClickDrag('Primary', 931, 582, 931, 592)
    Sleep(100)
    MouseClick('Primary', 703, 576, 1) ;Select Huddersfield Royal Infirmary
    Sleep(100)
    MouseClickDrag('Primary', 931, 592, 931, 596)
    Sleep(100)
    MouseClick('Primary', 703, 592, 1) ;Select St. Lukes Hospital
    Sleep(100)
    Send('{CTRLUP}')
    MouseClick('Primary', 979, 564, 1) ;Click Add
    Sleep(100)
EndFunc   ;==>SetOrganisations

Func AddRTERule()
    MouseClick('Primary', 69, 657, 1) ;Click Rules...
    Sleep(100)
    MouseClick('Primary', 363, 228, 1) ;Click Type
    Sleep(100)
    MouseClick('Primary', 363, 266, 1) ;Click RTE
    Sleep(100)
    MouseClick('Primary', 363, 545, 1) ;Click New Rule
    Sleep(100)
    Send($RTERuleName) ;Enter Mnemonic
    Sleep(100)
    Send('{TAB}') ;Enter Description
    Send('{TAB}{TAB}{RIGHT}') ;Navigate to Rule tab
    Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{SHIFTUP}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}') ;Select the Operand 'Order Physician'
    Send('{SHIFTDOWN}{TAB}{SHIFTUP}{DOWN}{DOWN}{ENTER}') ;Select the Operator '='
    Send('{TAB}{TAB}{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}') ;Open the 'Order Physician' Datasource value dialog
    Send($LastName & ',' & $FirstName) ;Enter resource name
    Send('{ENTER}') ;Search resource
    Sleep(500)

    If PixelGetColor(697, 446, 0xF0F0F0) Then ;If resource is not found, cancel out
        Sleep(200)
        MsgBox(64, 'Error', 'Resource is not found, therefore this pool will not be saved and will cancel out. Click OK to continue.')
        _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Fail', 'I' & $Row)
        _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Resource not found. ' & $Notes, 'J' & $Row)
        Sleep(500)
        WinActivate('Scheduling Help')
        Sleep(500)
        Send('{ENTER}') ;Click OK
        Sleep(500)
        Send('{SHIFTDOWN}{TAB}{SHIFTUP}{ENTER}') ;Click Cancel
        Sleep(500)
        Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
        Sleep(500)
        WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
        Sleep(500)
        Send('{TAB}{ENTER}') ;Click Yes
        Sleep(500)
        WinActivate('Rules for Pool')
        Sleep(500)
        Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
        Sleep(500)
        MouseClick('Primary', 1259, 653, 1) ;Click Cancel
        Sleep(500)
    Else
        Send('{TAB}{TAB}{DOWN}') ;Find resource
        Sleep(200)
        If PixelGetColor(725, 383, 0x3399FF) Then ;If there are multiple resources, cancel out
            Sleep(200)
            MsgBox(64, 'Error', 'There are multiple resources, therefore this pool will not be saved and will cancel out. Click OK to continue.')
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Redo', 'I' & $Row)
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Multiple resources. ' & $Notes, 'J' & $Row)
            Sleep(500)
            WinActivate('Scheduling Help')
            Sleep(500)
            Send('{TAB}{TAB}{ENTER}') ;Click Cancel
            Sleep(500)
            Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
            Sleep(500)
            WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
            Sleep(500)
            Send('{TAB}{ENTER}') ;Click Yes
            Sleep(500)
            WinActivate('Rules for Pool')
            Sleep(500)
            Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
            Sleep(500)
            MouseClick('Primary', 1259, 653, 1) ;Click Cancel
            Sleep(500)
        Else ;Select the resource
            Sleep(200)
            Send('{ENTER}') ;Select Order Physician
            ;MsgBox(0, '', 'save button clicks now')
            Send('{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}') ;Click Save
            Sleep(500)
            ;If rule already exists, cancel out
            ;If PixelGetColor(802, 433, 0xF0F0F0) Then ;Grey
            If PixelGetColor(554, 383, 0x1D40B7) Then ;Blue
                Sleep(500)
                MsgBox(64, 'Error', 'Rule already exists, therefore this pool will not be saved and will cancel out. Click OK to continue.')
                _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Redo', 'I' & $Row)
                _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Rule already exists. ' & $Notes, 'J' & $Row)
                Sleep(1000)
                WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
                Sleep(500)
                Send('{ENTER}') ;Click OK
                Sleep(500)
                Send('{TAB}{TAB}{ENTER}') ;Click Close
                Sleep(500)
                Send('{TAB}{ENTER}') ;Click Yes
                Sleep(500)
                Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
                Sleep(500)
                MouseClick('Primary', 1259, 653, 1) ;Click Cancel
            ElseIf PixelGetColor(572, 382, 0xAD0909) Then ;Red
                MsgBox(0, '', 'Syntax error.')
            Else
                MsgBox(0, '', 'Rule can be saved.')
                _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Complete', 'I' & $Row)
                _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Success. ' & $Notes, 'J' & $Row)
                Send('{SHIFTDOWN}{TAB}{SHIFTUP}{ENTER}') ;Click Close
                Sleep(500)
                Send('{SHIFTDOWN}{TAB}{TAB}{SHIFTUP}') ;Navigate to Name field
                Sleep(100)
                Send($RTERuleName) ;Enter RTE Rule Name just created
                Sleep(100)
                Send('{TAB}{ENTER}') ;Click Search
                Sleep(100)
                Send('{TAB}{TAB}{TAB}{TAB}{DOWN}{DOWN}') ;Select RTE Rule just created
                Sleep(100)
                Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Add >
                Sleep(500)
                MouseClick('Primary', 1148, 654, 1) ;Click Apply
                Sleep(500)
                MouseClick('Primary', 45, 91, 1) ;Click Commit
                Sleep(500)
                Send('{ENTER}') ;Click OK
                Sleep(1000)
            EndIf
        EndIf
    EndIf
EndFunc   ;==>AddRTERule

Func EndProgram()
    Exit
EndFunc   ;==>EndProgram

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

you want to to stop the script using hotkeys

right?

I ran your script and hotkeyset worked fine while auto it window is minimized.. please could you be more specific???

HotKeySet('e', 'EndProgram')
Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Yes that's correct. Forgive me for asking what may be a stupid question, but this specific hotkey to be actioned upon only requires the letter e to be entered on the keyboard with no other key needing to be entered right?

If so, this did not work for me while I ran the entire script copied in previously. It also did not work for the simple script below.

MsgBox(65, "Update", "Hello!")

HotKeySet('e', 'EndProgram')

Func EndProgram()
    Exit
EndFunc   ;==>EndProgram

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

This script ends right after the MsgBox is closed so am unsure what you are trying to say here.

In case you mean that the letter e doesn't close the MsgBox then:

  1. MsgBox() is a blocking function and indeed can't be interupted by a HotKeySet(). Workaround is to build your own MsgBox() func with a GUI.
  2. In your case it would have never worked anyways since the HotKey isn't set yet when the MsgBox() is displayed. 

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted

Thanks for confirming, I assume there are other blocking functions going in my original script hence the hotkeysets do not work. I've updated my script to ask for my input after each cycle of the automation is completed, from whereby I can abort it as an option. Good enough for now. I'll have a try with a GUI workaround though for future projects, thanks again.

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

  • Similar Content

    • fosil
      OnAutoItExitRegister not working
      By fosil
      Hi all,

      I'm working on a relatively complex automation program and I need it to call a specific function when it is closed by a user. Ive resorted to "OnAutoItExitRegister" as i believe that's the only option available.

      This command works perfectly fine in a small scale test application I wrote, but once implemented in the final program that's much larger and divided over many files in many directories it no longer works. I don't get any error messages.

      My question is has anyone encountered an issue where implementation of this command in a large scale program gave them trouble? Does it matter where "OnAutoItExitRegister" is called and where the function is located? Currently they are both places in the main file that runs the whole program but it still doesn't work.

      Any help is appreciated
    • crushyna
      Error check implementation (problem with loop exit)
      By crushyna
      Hi everyone!
      I'm developing small testing tool for new software in my company.
      Tool itself is working correctly (it follows scripted test commands one by one), but I'm trying to develop an error checking function.

      Mechanics are simple: every time software (external) shows specific error (via window class), program asks for next step. Continue, or abort test (and return to main GUI)?
      The error check function is switched on/off via Checkbox in GUI.

      Here are some code fragments:

      Checkbox:
      Global $idCheckbox1 = GUICtrlCreateCheckbox("Enable TP.net error handling", 352, 40, 249, 17) GUICtrlSetFont(-1, 12, 400, 0, "Calibri") GUICtrlSetColor(-1, 0x000000)  
      Checkbox switch:
      GUISetState(@SW_SHOW) Local $Choosen While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idCheckbox1 If _IsChecked($idCheckbox1) Then $cSwitch1 = 1 Else $cSwitch1 = 0 EndIf Case $idAddTest (and so on...)  
      Function call:
      (alot of ElseIf commands...) ElseIf $aItem = $idOperatorIn Then WywolanieOkna() WinActivate($hFSO) ControlClick($hFSO, "", "[NAME:lblCashierNumber]") Sleep($Sleep_05) Send("0000019{Enter}19{Enter 2}") Sleep($Sleep_75) EndIf #EndRegion ### START ELSEIF ARMY ### Next If $cSwitch1 = 1 Then MsgBox( 0, "Error check!", "Error check ON!") /// just for testing purposes CheckError() Else Return EndIf EndSwitch WEnd
      Classic _IsChecked function:
      Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked  
      And Checkerror() function itself:
      Func CheckError() Local $Answer If ControlCommand($hMsgPanel, "", "[NAME:panelMsgBox]", "IsEnabled", "") Then ;~ Sleep($Sleep_05) $Answer = MsgBox(52, "Error!", "An error occured! Continue testing?") ;~ Sleep($Sleep_05) Switch $Answer Case 6 MsgBox(0, "Error!", "Test will now continue.", 3) Send("{Enter}") WinActivate($hWnd) Return Case 7 MsgBox(64, "Error!", "Test cancelled.", 5) $ElseIfArmyOff = 1 ControlClick($hMsgPanel, "", "[NAME:cmdOK]") WinActivate($AppName) #cs MsgBox( 0, "test1", $idTSList) Local $idTSListCopy For $i = 0 to _GUICtrlListView_GetItemCount($idTSList) - 1\ #ce $idTSListCopy = _GUICtrlListView_GetItemTextString($idTestCaseList, $LoopCount) ExitLoop EndSwitch EndIf Return 1 EndFunc ;==>CheckError
      Problem is: i can't make this function (CheckError() ) return to main gui state, that means: break the If/ElseIf loop.
      The switch is working correctly (MsgBox on error shows only when it's activated).
      Checkerror() function works correctly - recognizes the error, stops script until decision is made. But it doesn't terminate If/ElseIf loop.

      Any help appreciated!
    • Vivaed
      Running PS1 Script with Parameters
      By Vivaed
      Trying to automate the sideload of a Windows Store app via .ps1 script...
      RunWait(@ComSpec & ' /c' & 'C:\"WB Resources"\APP_Prod\Add-AppDevPackage.ps1') Above doesn't work... I assume this is trying to open in CMD.
       
      Normally we right click the .ps1 and open with powershell, then we have to type "A" to start the install, it installs and then type any yet to exit.
      However I cant get the powershell to even open.
      Kind of puzzled here, any suggestions would be a help.
      PS I also tried to convert the .ps1 to exe, but that was a huge failure... lol
    • khathiatz
      UninstallMe - Automatically destroy script
      By khathiatz
      UninstallMe will automatically destroy script running
      - With example files
      - Automatic, using file BAT and VBS to destroy, no GUI
       
       
      English: https://khathiatz.blogspot.com/2016/08/uninstall-me-en.html
      Tiếng Việt: https://khathiatz.blogspot.com/2016/07/uninstall-me.html
       
    • Comboku
      Exit function from "outsite" with button press
      By Comboku
      Hi Guys,
      I have written a little loop program that counts to whatever you choose in "Rounds". 

      (this is just a short version of my program, but it should cover what I try to achieve)

      I now want to be able to stop the counting by pressing the start/stop button. Unfortunately, autoit only registers my click on my button AFTER the func has ended.

      Do you guys have an idea how to stop the function? Maybe check if button was pressed in the loop? 


      Thanks,

      Comboku

       
       
       
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <IE.au3> #include <Array.au3> #include <File.au3> $Form1 = GUICreate("Looper", 355, 229, 435, 293) $StartStop = GUICtrlCreateButton("Start", 136, 184, 75, 25) $Rounds = GUICtrlCreateInput("1", 210, 40, 80, 21) $lRounds = GUICtrlCreateLabel("Rounds", 298, 42, 52, 18) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $StartStop If GUICtrlRead($StartStop) = "Start" Then GUICtrlSetData($StartStop, "Stop") GUICtrlSetState($Rounds, $GUI_DISABLE) Call("Loop") ElseIf GUICtrlRead($StartStop) = "Stop" Then ExitLoop MsgBox(0, "Info", "Stopped") Else MsgBox(0, "Info", "Error") EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Loop() $LoopTimes = GUICtrlRead($Rounds) For $i = 1 To $LoopTimes MsgBox(0, "Info", "LET US COUNT: " & $i) Sleep("2000") Next GUICtrlSetData($StartStop, "Start") GUICtrlSetState($StartStop, $GUI_ENABLE) GUICtrlSetState($Rounds, $GUI_ENABLE) EndFunc