Jump to content

pausing script with a key


 Share

Recommended Posts

Hello,

I am a bit new to AutoIT, written the following script but I want to pause/resume when I click on mouse click but I want to pause instantly.

 

#include <AutoItConstants.au3>

Global $Paused

HotKeySet("^!w","pause")
HotKeySet("^!s","start")

$Paused = False

While 1 = 1
   If $Paused = False Then
      Send ("{4 DOWN}")
      Sleep (1500)
      Send ("{4 UP}")
      Sleep(200)
      Send("3")
      Sleep(200)
      Send("2")
      Sleep(200)
      Send("{SHIFTDOWN}")
      Sleep(50)
      MouseClick("LEFT")
      Sleep(100)
      MouseClick("RIGHT")
      Send("{SHIFTUP}")
   Else
      Sleep(5000)
   EndIf
Wend

Func pause()
   $Paused = True
EndFunc

Func start()
      $Paused = False
EndFunc

Any help is appriciated

Link to comment
Share on other sites

  • Moderators

As you only check $Paused at the top of your If loop, it is going to go through all of those steps before checking again - thus it will never be "instant". If you want it instant you would either have to check the value of $Paused after every step or look at AdLibRegister.

On a wider note, what are you trying to accomplish? Using a bunch of Sends and Sleeps is not going to be very consistent; depending on what you're trying to do there is probably a much better way.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Add this chunk right after the While 1 = 1

If _IsPressed(1) Then; Left Mouse Button
    While _IsPressed(1)
        Sleep(20)
    WEnd
    If $Paused = True Then
        $Paused = False
    Else
        $Paused= True
    EndIf
EndIf; _IsPressed(1)

You'll also need to include <Misc.au3> at the top where you're including things.

Edited by Xandy
Link to comment
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
 Share

  • Recently Browsing   0 members

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