AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pause
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Bobbyandck
Guest





PostPosted: Sat Mar 05, 2005 4:22 pm    Post subject: Pause Reply with quote

Hello,

I have a problem with assigning a hot key to the pause function, my code is the following:

Code:

Pause::Pause
Loop, 5
 {
...
}


(instead of the "..." I have some basic run, sleep, statusbarwait and mouseclick functions)

If I take off the first line, it works perfectly well but if I leave it the script does not continue to the second line.

Thank you very much for any helo you can give me
Back to top
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Sat Mar 05, 2005 4:54 pm    Post subject: Reply with quote

When you assign a function directly to the hotkey like that, a return is implicit after the function. To explain more clearly, this is what AutoHotkey sees when you do that:


What you code:
Quote:
Pause::Pause
Loop, 5
{
...
}



What AutoHotkey sees:
Quote:
Pause::
Pause
return
Loop, 5
{
...
}



So, fix it like this:
Quote:
Pause::
Pause
Loop, 5
{
...
}
Back to top
View user's profile Send private message
Bobbyandck



Joined: 05 Mar 2005
Posts: 5

PostPosted: Sat Mar 05, 2005 7:46 pm    Post subject: Reply with quote

I am sorry, but I did exactly like you told me but it still doesn't execute the rest of the program.

It works to pause and to unpause the script.

Thank you for your help.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Mar 06, 2005 2:31 am    Post subject: Reply with quote

I tried the following and it seems to work okay. Press Ctrl-Alt-P to pause, then press it again to resume. You get two MsgBoxes because there is the original paused thread (now unpaused) and the second thread that actually did the unpausing.

^!p::
pause
msgbox unpaused
return

If you want to pause a loop by pressing a hotkey, please read the FAQ, which has working example.
Back to top
View user's profile Send private message Send e-mail
Bobbyandck



Joined: 05 Mar 2005
Posts: 5

PostPosted: Sun Mar 06, 2005 7:41 pm    Post subject: Reply with quote

none of the two work.

The one you proposed had the same problem as previously, It doesn't execute the following loop.

The one in the FAQ, reacts like this:
- start script
- nothing happens (other than the little green icon in the bottom left part of the screen (sorry, I don't remember the name in english))
- I press win+z :blinking + execution of program
- I press win+z 2nd time : program continues.

So it works only to start the script and not to stop it (the whole purpose)

Except if I misunderstood where should I put my loop into it.
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Sun Mar 06, 2005 8:01 pm    Post subject: Reply with quote

Your problem might be that you sit behind your monitor. Otherwise the little green icon appears in your right, bottom part of the screen (tray) Very Happy
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Sun Mar 06, 2005 8:09 pm    Post subject: Reply with quote

Only if you constrain yourself to the ghastly Explorer shell. Litestep lets you organize your desktop the way you want.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Mar 06, 2005 8:47 pm    Post subject: Reply with quote

Bobbyandck wrote:
The one in the FAQ, reacts like this:
- I press win+z 2nd time : program continues.
So it works only to start the script and not to stop it (the whole purpose)
I tested the one in the FAQ and pressing Win+Z the second time stops it. This is on Windows XP. Which OS are you using?
Back to top
View user's profile Send private message Send e-mail
Bobbyandck



Joined: 05 Mar 2005
Posts: 5

PostPosted: Mon Mar 07, 2005 10:52 pm    Post subject: Reply with quote

Sorry everyone, yes I meant at the bottom right.

I am under Windows XP.

Could you please tell me where should I put my script in the one of the faq ? I think it might be that the problem.

Thank you very much.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Tue Mar 08, 2005 12:30 am    Post subject: Reply with quote

You didn't post enough of a script to work with. Have you tried to integrate it on your own?

Also, if you plan to do more with AutoHotkey than just this one hotkey, it's worth your while to read the Quick-start Tutorial if you haven't already.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Tue Mar 08, 2005 12:43 am    Post subject: Reply with quote

I tried it, too, and it works on my Win2K laptop as expected:
Code:
cnt = 0
Pause::
Pause
Loop 5
{
   cnt++
}
MsgBox %cnt%
return
The first Pause key fires the hotkey, which does not do anything, but get Paused (the green AHK tray icon turns red). The second time pressing the Pause key fires the Pause hotkey again. The thread gets "unpaused", that is, it first continues, what the last time it could not, and shows a message: 5. Upon clicking OK, the new thread gets its chance, and runs the loop another five times, and at the end it shows the message: 10.
Back to top
View user's profile Send private message
Bobbyandck



Joined: 05 Mar 2005
Posts: 5

PostPosted: Tue Mar 08, 2005 1:51 pm    Post subject: Reply with quote

This is my script:
Code:
Loop, 11
{
Run, http://www.braingle.com/games/foodfight/fight.php?grade=2&op=2
Sleep, 400
StatusBarWait, Done
 Loop, 10
 {
 MouseClick, left, 1000, 588
 Sleep, 800
 StatusBarWait, Done
 }
Run, http://www.braingle.com/games/foodfight/bank.php
Sleep, 600
StatusBarWait, Done
MouseClick, left, 700, 571
Sleep, 600
StatusBarWait, Done
}


What it does is to load a page, click on a link, wait for the page to load, repeat several times the two last steps, go on an other page, click on a link, wait, and start all over again several times.

What I wanted is to pause(or stop) the script if the following happens:
- another window opens (MSN Messenger, news, virus alert)
- I have to do something urgently and don't have the time to wait for the script to end
- the website doesn't load
etc.

Thank you very much for your help and am sorry that I am causing so many problems.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Wed Mar 09, 2005 4:48 pm    Post subject: Reply with quote

One problem with the script above is that StatusBarWait requires a WinTitle parameter if there is no last found window.

In general, if you can't get a complex script to work, it helps to simplify it into smaller parts that you can get to work. When all the parts are working, that's the time to combine them.
Back to top
View user's profile Send private message Send e-mail
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Mar 09, 2005 6:47 pm    Post subject: Reply with quote

Another good way to unravel complex scripts is clever use of OutputDebug. If we had an English wiki, I'd write a tutorial for it. It's very simple and very useful once you get the hang of it.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Thu Mar 10, 2005 5:51 pm    Post subject: Reply with quote

Here is a simple way for Pause/Resume/End a loop with the Pause and End keys. Alt-z starts an infinite loop. As an example, a counter is kept incremented and a MsgBox shows its current value for a second (or until you click OK).

When the Pause key is hit, it sets the variable "stop" to True, the next time back to False, and so on.

When the running loop sees "stop" being True, it goes to sleep for 0.1 second, and then checks it again. When the Pause hotkey sets "stop" to False, the loop starts again executing the active code inside.

When the key End is hit, the End hotkey sets the "end" variable to True (1). If the loop is running, it will stop. Hitting Alt-z again starts the whole process all over.
Code:
~Pause::
stop := not stop
return

~End::
end = 1
return

!z::
stop = 0
end  = 0
loop
{
   if stop
      sleep 100
   else {
      cnt++             ; your code here
      MsgBox,,,%cnt%,1
   }
   if end
      break
}
return
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group