ErkanA

pausing script with a key

4 posts in this topic

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

Share this post


Link to post
Share on other sites

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

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