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 

Intended behavior of Pause?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
AiKscroll



Joined: 06 Jun 2005
Posts: 179
Location: Northern Virginia

PostPosted: Wed Dec 20, 2006 3:24 am    Post subject: Intended behavior of Pause? Reply with quote

I wrote a script that essentially has two keys do the same thing, pause the script. But to unpause the script I nust press the key that was not pressed to pause the script. Is this supposed to happen?

Code:

loop
msgbox, I'm going to keep bothering you until you press Pause or F2

$F2::
Gosub, PauseScript
return

$Pause::
Gosub, PauseScript
return

PauseScript:
pause
return

_________________
_AiK
Back to top
View user's profile Send private message AIM Address
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Dec 20, 2006 4:24 am    Post subject: Reply with quote

That's because Pause doesn't affect the whole script, only the currently running thread. As a side-effect of this, though, any threads that the current thread interrupted will have to wait until it is unpaused and finishes, so essentially you've paused the whole script at that point. What's happening here is that, when you press one of the hotkeys, it runs until it finds Pause, at which point it pauses, unsurprisingly. So that hotkey's thread is frozen, and the thread it interrupted - the infinite msgbox loop - is also effectively frozen. Now what happens when you press that key again? AutoHotkey sees that the hotkey is already running, so it does nothing, unless you set #MaxThreadsPerHotkey higher than 1. The other hotkey has no problem running, and when it gets to Pause it unpauses the underlying thread.

So, to fix it, you need to set #MaxThreadsPerHotkey to 2:

Code:
#MaxThreadsPerHotkey 2

Loop
   MsgBox I'm going to keep bothering you until you press Pause or F2.
return

$F2::Pause

$Pause::Pause


Note that I simplified it; if you were using the label jump to accomplish some other purpose, my apologies. If not, though, it is unnecessary.
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
Page 1 of 1

 
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