Jump to content
Masum

Exit / Stop Script

Recommended Posts

Masum

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
Masum

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
Jos

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

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Masum

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
Masum

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
Jos

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Masum

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
232showtime

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
Masum

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
Jos

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

  • Like 1

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Masum

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

    • ademon
      By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


    • lenclstr746
      By lenclstr746
      Hi guys,
      Some functions of my script are running slowly. Very slow. What is the reason?
      My Code:
      <snip>
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I found this function in the Internet
      It is to play audio files from  the compiled script
      I did not understand just one thing on this function
      func play($name, $wait = 0) local Const $SND_RESOURCE = 0x00040004 local Const $SND_ASYNC = 1 ; Play the file - the script will pause as it sounds if $wait = 0 then DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC)) else DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", $SND_RESOURCE) endIf return 1 endFunc What I did not understand was this variable
      local Const $SND_RESOURCE = 0x00040004 I know that this variable is contains the resource name
      But what if I want to change the name of the resource what i'll do?
      can i do that?
      Thanks in advance
       
    • krasnoshtan
      By krasnoshtan
      Hello forum users!
      At some point I had a need to restart my script. Is it possible to do this with autoit or do I need to connect additional scripts like .cmd or .bat?
      For example: i have only script.au3 and it's running. Wich code shoud i use to exit from the script and start it again?
×