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

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

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

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

    • Eggsplorer
      By Eggsplorer
      Hi,
      Ich hab ein Script für Windows Updates, dass nach dem OOBE aufgerufen werden soll. Run/RunOnce ist daher nicht möglich.
      Stattdessen möchte ich das Script in den Autostart schreiben lasse. Wenn die OOBE beendet wird und der Administrator angemeldet wird, soll das Update-Script einmalig aufgerufen werden und sich anschl. selbst löschen.
      Lang rede, kurzer Sinn:
      Wie kann ich folgendes Script in den Autostart schreiben?
      RunWait(@ComSpec & " /c " & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\UA\Scripts\win-updates.ps1 -MaxUpdatesPerCycle 100 -RestartRequired 1", "") Ich würde ungern eine BAT oder EXE reinkopieren, da ich es unsauber finde. Die müsste ja auch zusätzlich irgendwo liegen.
      Danke
      Eggsplorer
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • LOWLIFE
      By LOWLIFE
      This is a personal project to log into several facebook accounts and send a message to a specific person on their birthday. I need to stop a script in a few different ways for several different reasons. For example, it might start sending the email to the wrong account, it might do something other than send a message, it might fail to logout of one account, etc. 
      1) Pause the script at it's exact location with a resume feature in case I need to put it on hold while I do another task. 
      2) Pause the script at it's current location with the option to start over or execute another part of the script (example in GUI with multiple buttons). 
      Also, is there a way to interact with menus? If I log into facebook how can I force it to go straight to sending a message to the proper person? I tried automating a mouseclick but the window opens in different places. I also tried searching for specific text and I couldn't get any information from the windows info tool on the facebook page. 
      Also, how do I get my code in here to show like it does in my editor? (scite)
      Thanks for looking at it, and any help/suggestions I sgreatly appreciated!
      <snip>
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it