Jump to content

OnAutoItExitRegister() doesn't fire when exiting a console/cui app - is it possible to capture that event?


Recommended Posts

Posted (edited)

I have a small demo script, as shown below. The ExitHandler() function fires correctly in the following scenarios:

  • When allowing the script to end naturally on its own
  • When exiting the script via the tray icon

The ExitHandler() does NOT fire correctly in these scenarios:

  • When compiled as a console ("cui") application and hitting the close button on the console window
  • When compiled as a console ("cui") application and pressing CTRL+C in the console window

Do you know if it's possible to trigger any code in these last two scenarios, or does that force quit the script immediately?

Either way, it would be good to have the documentation updated to mention this. I'd be happy to contribute documentation if I knew how.

#AutoIt3Wrapper_Change2CUI=y
OnAutoItExitRegister("ExitHandler")
ConsoleWrite("Script started. Waiting 6 seconds." & @CRLF)

Sleep(6000)

Func ExitHandler()
    ConsoleWrite("Exit detected." & @CRLF)
    MsgBox(0, "Exit!", "Exit detected.")
EndFunc

 

Edited by Coder4

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...