Jump to content

Use a key to pause/unpause program


 Share

Recommended Posts

Can someone help me, i have no idea of making the program stop running =P

My programs spams out some text randomly automaticly for fun, then some times i wish to have a pause fuction for it.

so it disables/pauses all the programs functions untill i press the same or another key to make the program run again.

Without right clicking the little blue icon at the menu bar on my pc.

Annyone got something that might help me?

Link to comment
Share on other sites

Can someone help me, i have no idea of making the program stop running =P

My programs spams out some text randomly automaticly for fun, then some times i wish to have a pause fuction for it.

so it disables/pauses all the programs functions untill i press the same or another key to make the program run again.

Without right clicking the little blue icon at the menu bar on my pc.

Annyone got something that might help me?

Straight from hotkeyset helpfile http://www.autoitscript.com/autoit3/docs/f...s/HotKeySet.htm

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")

;;;; Body of program would go here ;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc
Link to comment
Share on other sites

Straight from hotkeyset helpfile http://www.autoitscript.com/autoit3/docs/f...s/HotKeySet.htm

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")

;;;; Body of program would go here ;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc
oÝ÷ Ûú®¢×v÷öÙbëaz¥¥ø¥yìZ^¢yrmçºÇ¶§Ø^~éܶ*'¶¸ êÞu¼­áè´§²Iël¥u·¦x¦jX¬µ8^"rÈhºW[z)íé{ªç§qæ¬ç!jÊh²Èàn¶ØZµ×©zwl¢{az«¦¡ûazÇ+H笰̩­çÞ­éÜ{
.ØZ½æÞzv®¶­sd÷D¶W6WBgV÷C·µU4WÒgV÷C²ÂgV÷CµFövvÆUW6RgV÷C²¤vÆö&Âb33cµW6VBÒG'VRÂb33c¶âÒ ¥vÆR¢bb33cµW6VBFVà¢FööÅFb33µ67&B2W6VBâââb33²¢VÇ6P¢FööÅFb33µ67&B'Væææs¢b33²fײb33c¶â¢VæD`¢6ÆVWS¥tVæ@ ¤gVæ2FövvÆUW6R¢b33cµW6VBÒäõBb33cµW6V@¤VæDgVæ0

:lmao:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

I don't like the helpfile example, only because I think the function triggered by the HotKeySet() should be minimalist. The logic should be in the main sequence as much as possible. But that depends on the purpose of the script, I guess. My preference would have been:

HotKeySet("{PAUSE}", "TogglePause")
Global $Paused = True, $n = 0

While 1
     If $Paused Then
          ToolTip('Script is paused...')
     Else
          ToolTip('Script running: ' & $n)
     EndIf
     Sleep(500)
WEnd

Func TogglePause()
    $Paused = NOT $Paused
EndFunc

:ph34r:

You would still need a loop to pause it :lmao: ... Or place your entire script in the "Else" portion of the If/Then, but with those same amount of lines you could just use the Whle $Paused/Sleep(100)/WEnd in the TogglePause()... Afraid I don't quite understand your logic behind that.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You would still need a loop to pause it :lmao: ... Or place your entire script in the "Else" portion of the If/Then, but with those same amount of lines you could just use the Whle $Paused/Sleep(100)/WEnd in the TogglePause()... Afraid I don't quite understand your logic behind that.

Placing the part you want to pause/unpause entirely in the Else section is exactly what I was intending (keeping in mind this needn't be more than a function call or two). This still leaves other parts of the script running while pausing the part controlled by the IF clauses. The point was not about needing a loop or not, and is more about my style and practice (which may need correction), since it can certainly work either way.

My only point was that when you hit the HotKey, the script spends a minimal amount of time in that "interrupt state" and quickly gets back to the tasks it was doing. It is in that main sequence that I would (not must) put the logic to act on the current status of $Paused. The specific requirements for the script may dictate otherwise, but that is my preference. Just a preference.

Let's say for example you have a script that does A, B, and C in a loop, but you want to be able to pause B without effecting the rest of the script:

HotKeySet("{PAUSE}", "TogglePause")
Global $Paused = False

; ==  Main Sequence  ==
While 1
     _A() ; Do A
     If Not $Paused Then _B() ; Do B
     _C() ; Do C
     Sleep(500)
WEnd

; ==  Local Functions  ==
Func _A()
     ; Do A
EndFunc

Func _B()
     ; Do B
EndFunc

Func _C()
     ; Do C
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
EndFunc

I'm not a prgrammer (to state the obvious), so I guess this comes from starting out as a hardware guy on real-time military stuff vice batch proccessing civilian stuff. Anything that caused your system to remain in an interrupt state and not get quickly back to task state was either a bug or a malfunction, and never by design. I'm sure that bias is unhelpfull in other situations (and maybe in AutoIT) and would need to be schooled on doing it differently.

You teach good, Me try learn good! :ph34r:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Placing the part you want to pause/unpause entirely in the Else section is exactly what I was intending (keeping in mind this needn't be more than a function call or two). This still leaves other parts of the script running while pausing the part controlled by the IF clauses. The point was not about needing a loop or not, and is more about my style and practice (which may need correction), since it can certainly work either way.

My only point was that when you hit the HotKey, the script spends a minimal amount of time in that "interrupt state" and quickly gets back to the tasks it was doing. It is in that main sequence that I would (not must) put the logic to act on the current status of $Paused. The specific requirements for the script may dictate otherwise, but that is my preference. Just a preference.

Let's say for example you have a script that does A, B, and C in a loop, but you want to be able to pause B without effecting the rest of the script:

HotKeySet("{PAUSE}", "TogglePause")
Global $Paused = False

; ==  Main Sequence  ==
While 1
     _A() ; Do A
     If Not $Paused Then _B() ; Do B
     _C() ; Do C
     Sleep(500)
WEnd

; ==  Local Functions  ==
Func _A()
     ; Do A
EndFunc

Func _B()
     ; Do B
EndFunc

Func _C()
     ; Do C
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
EndFunc

I'm not a prgrammer (to state the obvious), so I guess this comes from starting out as a hardware guy on real-time military stuff vice batch proccessing civilian stuff. Anything that caused your system to remain in an interrupt state and not get quickly back to task state was either a bug or a malfunction, and never by design. I'm sure that bias is unhelpfull in other situations (and maybe in AutoIT) and would need to be schooled on doing it differently.

You teach good, Me try learn good! :lmao:

Thank you *All*

just that i got 1 problem that makes me unsure to determin if this works or not... you asid its only pause the scrip for a little time, i wanna chage it so when i press pause/break button it will stop/pause the B section for about 60 seconds..

Thank you in advance

(i know i'm such a horrible beginner at this T.T)

Link to comment
Share on other sites

Thank you *All*

just that i got 1 problem that makes me unsure to determin if this works or not... you asid its only pause the scrip for a little time, i wanna chage it so when i press pause/break button it will stop/pause the B section for about 60 seconds..

Thank you in advance

(i know i'm such a horrible beginner at this T.T)

Small change to do that. This will pause B for 30sec, but keep running A and C in the meantime:

HotKeySet("{PAUSE}", "TogglePause")
Global $Paused = 0

; ==  Main Sequence  ==
While 1
     _A() ; Do A

     If $Paused Then
          If TimerDiff($Paused) >= 30 * 1000 Then $Paused = 0
     EndIf
     If Not $Paused Then _B() ; Do B

     _C() ; Do C

     Sleep(500)
WEnd

; ==  Local Functions  ==
Func _A()
     ; Do A
EndFunc

Func _B()
     ; Do B
EndFunc

Func _C()
     ; Do C
EndFunc

Func TogglePause()
    $Paused = TimerInit()
EndFunc

:lmao:

Edit: Tweak for cleaner code.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

I understand the logic fine, and it makes perfect sense. I can see this specifically on a case specific basis. Thanks for explaining.

P.S. - I see you always say you're not a programmer, 99% of us aren't :lmao:, but you have wonderful insight :ph34r:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

...you have wonderful insight :geek:

But no dancing spider on my chest! This makes me feel inadequate... :lmao:

All seriousness aside, thanks. I take that as a great compliment.

:ph34r:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...