AutoHotkey Community

It is currently May 25th, 2012, 1:27 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: April 4th, 2004, 12:49 am 
Baisically, I have a script set to loop and click at different locations every few seconds, which looks like this:
Code:
#x::
Loop 100,
{
LeftClick,  530,  378
Sleep, 100
Send, Text
Sleep, 100
LeftClick,  472, 415
Sleep, 100
LeftClick,  520,  552
Sleep, 100
LeftClick,  470,  580
Sleep, 100
}


It does indeed need to loop roughly this fast to get the desired effect. However, this poses a problem when I want to stop the macro. Is there any way to make the macro stop looping when I press the macro hotkey again, or is there a universal pause all macros hotkey?

Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2004, 1:27 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
There are at least two approaches. The first is to make a new hotkey that pauses the entire script. For example, this makes Ctrl-Alt-p do that:

^!p::pause ; toggle the pause state off and on

The other approach is to use a variable to make your #x hotkey multi-purpose, so that pressing it again will turn off the looping activity. Here's how to do it:

Code:
; Allow multiple threads so that this hotkey can "turn itself off":
#MaxThreadsPerHotkey 2
#x::
#MaxThreadsPerHotkey 1
if keep_x_running = y
{
     keep_x_running = n  ; Signal the other thread to stop.
     return
}
keep_x_running = y
Loop 100,
{
    if keep_x_running = n  ; Another thread signaled us to stop
        return
    LeftClick,  530,  378
    Sleep, 100
    Send, Text
    Sleep, 100
    LeftClick,  472, 415
    Sleep, 100
    LeftClick,  520,  552
    Sleep, 100
    LeftClick,  470,  580
    Sleep, 100
}



In the above, you can repeat the following section more often (e.g. after every sleep) if you need the stopping to be more instantaneous:

if keep_x_running = n
return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 29th, 2004, 7:42 pm 
Offline

Joined: May 29th, 2004, 7:13 pm
Posts: 4
I have 2 loops of clicking the mouse.

How can I cancel and stop any of the looping hotkeys?
Thank you.


^!z::
Loop, 50
{
Sleep, 3800
MouseClick, left, , , 1
}
return


^!m::
Loop, 400
{
Sleep, 4000
MouseClick, left, , , 1
}
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2004, 9:21 pm 
Offline

Joined: March 2nd, 2004, 10:10 pm
Posts: 443
Location: SLC, Utah
Code:
^!z::
Loop, 50
{
  Sleep, 3800
  MouseClick, left, , , 1
  if zloop = 1
  {
    zloop = 0
    break
  }
}
return


^!m::
Loop, 400
{
  Sleep, 4000
  MouseClick, left, , , 1
  if mloop = 1
  {
    mloop = 0
    break
  }
}
return

^!s::
zloop = 1 ; Tell the ^!z Loop to stop
mloop = 1 ; Tell the ^!m Loop to stop
return

thanks,
beardboy


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2004, 9:23 pm 
Offline

Joined: April 5th, 2004, 7:24 pm
Posts: 98
Location: Connecticut USA
ctrl j stops the loop

Code:

^!m::
Loop, 40
{
   if stopit = 1
      {
      stopit = 0
      break
      }
Sleep, 1000
MsgBox, 0, ,  looping here, .6
}
return

^j::
   MsgBox, 0, ,stopit !, .6
   stopit = 1
return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 30th, 2004, 5:26 pm 
Offline

Joined: May 29th, 2004, 7:13 pm
Posts: 4
Thank you for your advise.

How do I stop and cancel in the middle of this repeating 100 keystroke?

^!a::
SetKeyDelay, 5000
send, {a 100}
return

Thank you.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2004, 8:43 pm 
Offline

Joined: April 5th, 2004, 7:24 pm
Posts: 98
Location: Connecticut USA
try this

Code:
^!m::
stopit = 0
Loop, 3
{
   if stopit = 1
      exit
   MsgBox, 0, ,starting loop , .6
   loop, 20
      {
      sleep, 444
      if stopit = 1
         {
         MsgBox, 0, ,stopit !, .6
         break
         }
      send, %a_index% {enter}   
      }
Sleep, 1544
}
return

!j::
   
   stopit = 1
return



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2004, 1:05 pm 
Offline

Joined: April 5th, 2004, 7:24 pm
Posts: 98
Location: Connecticut USA
you can also toggle a timer on or off, as shown below.

warning: run the script in notepad window, the script sends {enter} keys.

Code:
run notepad.exe
Rshift & k::
settimer, loopit, 5000

loopit:
MsgBox, 0, ,starting loop , .6
   loop, 30
   {
   sleep, 20
   if stopit = 1
      {
      stopit = 0
      MsgBox, 0, ,stopit !, .6
      Break
      }
   send, %a_index% {enter}   
   }
Sleep,  44
return

rshift & l::
   stopit = 1
   settimer, loopit, off
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2004, 1:25 pm 
Offline

Joined: April 5th, 2004, 7:24 pm
Posts: 98
Location: Connecticut USA
this uses gosub to loop without initial delay.

you can also toggle a timer on or off, as shown below.

warning:
run the script in notepad window, the script sends {enter} keys.



Code:
run notepad.exe
!r::reload


Rshift & k::
   settimer, loopit, 5000
   gosub,  loopit
return

rshift & l::
   stopit = 1
   settimer, loopit, off
return

loopit:
MsgBox, 0, ,starting loop , .6
   loop, 30
   {
   sleep, 20
   if stopit = 1
      {
      stopit = 0
      MsgBox, 0, ,stopit !, .6
      Break
      }
   send, %a_index% {enter}   
   }
Sleep,  44
return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 31st, 2004, 4:30 pm 
Offline

Joined: May 29th, 2004, 7:13 pm
Posts: 4
Thank you.

I see we cannot stop this repeat send command.
Sounds like this command should be able to do emergency stop or cancel.
me think!

send, {a 100}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2004, 6:51 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Quote:
I see we cannot stop this repeat send command.
send, {a 100}

To make a Send interruptible, as in jamestr's examples, enclose the command in a loop instead:
Loop, 100
{
Send, a
}

Then any other hotkey that does an ExitApp, or that notifies the loop to stop via global variables such as in jamestr's examples, will terminate the loop.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: stop send command
PostPosted: June 1st, 2004, 5:50 pm 
Offline

Joined: May 29th, 2004, 7:13 pm
Posts: 4
I see.
But good design, the repeat "send" should be able to stop or cancel, instead of the loop requirements.
Me think.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: AndyJenk, azure, engunneer, KenC, Prankie, Pulover, toddintr and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group