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

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

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

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

    • kawliga751
      By kawliga751
      I am attempting to run an Autoit.exe with schtasks every weekday @ 9:05 am.
      I have the below
      C:\>SchTasks /Create /TN "P10Run" /TR "O:\AUTOIT\P40 Run.au3" /SC WEEKLY /D MON, TUE,WED,THU,FRI /ST 09:05:00 SUCCESS: The scheduled task "P10Run" has successfully been created. I also did a "test" run :
      C:\>Schtasks /Run /TN "P10Run SUCCESS: Attempted to run the scheduled task "P10Run". But when I run my query to verify success my "Last Result" seems to indicate that the script did not run:
      C:\>SCHTASKS /QUERY /FO LIST /V /TN "P10RUN" Folder: \ HostName: xxxxxxxxxxxxxxxx TaskName: \P10RUN Next Run Time: N/A Status: Could not start Logon Mode: Interactive only Last Run Time: 6/14/2017 9:08:56 AM Last Result: -2147024894 Author: xxxxxxx Task To Run: O:\AUTOIT\P40 Run.au3 Start In: N/A Comment: N/A Scheduled Task State: Enabled Idle Time: Disabled Power Management: Stop On Battery Mode, No Start On Batterie s Run As User: xxxxxxxxx\xxxxxxxx Delete Task If Not Rescheduled: Enabled Stop Task If Runs X Hours and X Mins: 72:00:00 Schedule: Scheduling data is not available in this f ormat. Schedule Type: Weekly Start Time: 9:05:00 AM Start Date: 6/14/2017 End Date: N/A Days: MON, TUE, WED, THU, FRI Months: Every 1 week(s) Repeat: Every: Disabled Repeat: Until: Time: Disabled Repeat: Until: Duration: Disabled Repeat: Stop If Still Running: Disabled C:\> Is there something missing in my command? Also is there a better way to make sure that the script does in fact sun successfully?
      Thanks In Advance! 
    • chacoya121
      By chacoya121
      please help, how to write script for multiple choice question
      in GUI
      -single program
      -add more question to program
      example:
      1. this is the question
      a. answer a
      b. answer b
      c. answer c
      d.answer d
      - 300 questions +  700 answers
      please give me some tips to create a script
      read and write file from notepad, that mean u need notepad attach?
       
       
    • IamKJ
      By IamKJ
      So I have a lot of different functions in the little program I'm making.  Most of them use the Do statement, such as finding images, clicking buttons, etc.
       
      The question I have is how would I be able to both
      1) Create a hotkey to pause whatever I am doing at the moment.  If I have to put something into every function in the program, I don't mind.
      2) Create a hotkey to exit whatever I am doing and stop all loops or commands and bring back the main GUI?
    • ur
      By ur
      I have created an exit function and registered using OnAutoItExitRegister.But it is not running when I close the app from taskbar or even with normal exit during end.
       
      Below is the part of code and the included files.
      #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <Date.au3> #include <file.au3> #include <Array.au3> #include <String.au3> OnAutoItExitRegister("Exit_Program") Func Exit_Program() LoggingMainScr("Entered Exit_Program") Local $exitmethod = ["Natural closing", "close by Exit function", "close by clicking on exit of the systray","close by user logoff","close by Windows shutdown"] ExitProgram("Exit with exit code: "& @exitCode & " And because of: " & $exitmethod[@exitmethod],@exitmethod) EndFunc Func ExitProgram($sReason="Exit by user",$sCode=0) LoggingMainScr($sReason) if $sCode <> 0 then LoggingMainScr("stopped before completion") FileDelete(@ScriptDir&"\Machines*.txt") FileDelete(@ScriptDir&"\PsExec.exe") FileDelete(@ScriptDir&"\HyperVMachines.ps1") FileDelete(@ScriptDir&"\VMwareMachines.ps1") EndFunc Func LoggingMainScr($sMessage) LoggingDefault($sMessage,@ScriptDir&"\MainScr_Logging.log") EndFunc Func LoggingDefault($sMessage,$sLogFile=@ScriptDir&"\Logging.log") If $sMessage = "" Then FileWriteLine($sLogFile, "") Else FileWrite($sLogFile,_NowCalc() & " :: " & $sMessage&@CRLF) EndIf EndFunc Any suggestion.
       
    • Meobdg
      By Meobdg
      Hi, I have a problem, my functions do not work with each other. Separately, each works very well. Features that do not work together it's loot() and  pos1(). It looks that after spreadsheet function loot() script stops working even though everything is in the While 1-Wend loop.  Can someone help me please?