Sign in to follow this  
Followers 0
Guest cybergeek

Keyboard Combination To Stop Script?

7 posts in this topic

Hi guys. I wondered something. I want to use a script that doesnt include any pauses in it so that the mouse continually moves and clicks where I want it. The problem is that I am not able to get to the taskbar to stop the script from running because the mouse gets stuck in an endless routine. I wondered, does AutoIt include a way to stop a script using the keyboard? If so what is the key combination that needs to be pressed? Thank you so much for any help you can give me on this!

CyberGeek

Share this post


Link to post
Share on other sites



since 3.0.85 you can use a function called HotKeySet() to interrupt a script:

example:

HotKeySet("{pause}", "test")    ; Call function test() on PAUSE

While 1

... do your thing

Wend

Func test()

    MsgBox(0, "Test", "Test called")

EndFunc


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

#3 ·  Posted (edited)

since 3.0.85 you can use a function called HotKeySet() to interrupt a script:

example:

how to prevent the HotKeySet("{pause}", "test") running twice when i press PAUSE twice by mistake ???

or i wanna press "PAUSE" first to pause the bot, and press "Pause" secondly to resume the bot, how to do that ??

thx!

Edited by cxcio

Share this post


Link to post
Share on other sites

something like this ???

$pause=0

HotKeySet("{pause}", "PausePressed")

While 1

if $pause = 0 then

      sleep(200) ;.. do your thing

      splashtexton("Program","running")

else

      sleep(200) ;.. pausing

      splashtexton("Program","sleeping")

endif

Wend

Func PausePressed()

    if $pause=1 then

      $pause=0

    else

      $pause=1

    endif   

EndFunc


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

#5 ·  Posted (edited)

I like that code JdeB... Maybe I'll put something like the following in the unofficial docs tips/examples:

Global $Paused;default is zero (meaning False)
HotKeySet("{PAUSE}", "TogglePause");that's the Pause/Break keyboard key
HotKeySet("{ESC}", "Terminate")   ;that's the Escape keyboard key

SplashTextOn("myMsgScreen", "Paused", -1, -1, -1, -1, 1, "", 24, -1)

WinShow("myMsgScreen", "", @SW_HIDE)

While (1);infinite loop
   If $Paused then
      WinShow("myMsgScreen", "", @SW_SHOW)
   Else
      WinShow("myMsgScreen", "", @SW_HIDE)
  ; stuff to do goes here
  ; ...
   EndIf
Wend

Func TogglePause()
   $Paused = NOT $Paused
EndFunc

Func Terminate()
   Exit
EndFunc
Edit: converted tabs to spaces so it looks nice

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

What if you want to 'pause' at any point during the script (well the loop anyway), and not just the start?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

edit:

The previous script was designed to finish it's cycle before going in "pause"mode.

The below script will wait till you click OK to continue and will resume where it left of or Cancel to stop the script.

HotKeySet("{PAUSE}", "TogglePause");that's the Pause/Break keyboard key

While (1);infinite loop

; stuff to do goes here

sleep(200)

; ...

Wend

Func TogglePause()

  $rc=msgbox(1,"Paused","Click Ok to continue or Cancel to stop program")

  if $rc = 2 then exit

EndFunc

Edited by JdeB

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

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
Sign in to follow this  
Followers 0