By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt Exit Function

AutoIt Exit Function – create a custom exit function for your script.

Created: 2012-05-11 06:17

Creating a custom AutoIt Exit Function – just a quick little tip on how to create a exit function and bind it to a hotkey.

This function is using the AutoIt Exit Keyword to provide an easy way to terminate the running script at any time – sometimes you may need to hit the hotkey a few times for the script to react, this is likely due to the sleep somehow blocking AutoIt from catching hotkey presses.

Custom Exit Function

The way to set a hotkey is using the HotKeySet function of AutoIt.

;Assigns the HotKey to our custom exit function
HotKeySet("^!x", "MyExit")

$i = 0
While $i <= 10
  MouseClick("left", 200, 150, 1)

  ; Uncomment the below line to make the script click only 10 times, or until the hotkey is pressed.
   ; $i = $i + 1
  ; Uncomment the below line to make the script pause between clicks, the value is in milliseconds
   ; Sleep(5000)
WEnd

Func MyExit()
  Exit 
EndFunc