Jump to content
Sign in to follow this  
Hyflex

TogglePause not acting how it should - Script Included

Recommended Posts

Hyflex

Hey,

I have written the below and have got some problems with the "TogglePause" if I use HotKeySet it doesn't detect it when I'm using a different program, but with the _IsPressed it works but sometimes it stops and starts or starts then stops too fast like if I was to hold the button down it would start, stop, start, stop...etc

Please could someone help me fix it (also if there is a better way of doing what im doing please say.)

#include <misc.au3>

Global $Paused = True
Global $Active = True
Global $WinMoved = True

;HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

$Win01 = "01"
$Win02 = "02"

$Ance = "Ance.exe"
$CMP = "CMP.exe"

While 1
    If _IsPressed("13") Then
        Call("TogglePause")
        Sleep(1000)
    EndIf
    If $WinMoved = False Then
        If WinExists($Win01) Then
            WinMove($Win01, "", 0, 0)
            ConsoleWrite($Win01 & " " & "Moved" & @CRLF)
        EndIf
        If WinExists($Win02) Then
            WinMove($Win02, "", 1920, 0)
            ConsoleWrite($Win02 & " " & "Moved" & @CRLF)
        EndIf
        $WinMoved = True
    EndIf

    If $Active = False Then
        If $WinMoved = True Then
            If $Active = False Then
                If FileExists(@ScriptDir & "" & $CMP) Then
                    Run(@ScriptDir & "" & $CMP)
                EndIf
                If FileExists(@ScriptDir & "" & $Ance) Then
                    Run(@ScriptDir & "" & $Ance)
                EndIf
                ConsoleWrite("Started" & @CRLF)
                $Active = True
            EndIf
        EndIf
    EndIf
    Sleep(100)
WEnd


Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        If $Active = True Then
            If ProcessExists($CMP) Then
                ProcessClose($CMP)
            EndIf
            If ProcessExists($Ance) Then
                ProcessClose($Ance)
            EndIf
        EndIf
        If $WinMoved = True Then
            ConsoleWrite("Killed" & @CRLF)
        EndIf
        If _IsPressed("13") Then
            Call("TogglePause")
            Sleep(1000)
        EndIf
        $WinMoved = False
        $Active = False
        $ProcessesClosed = False
    WEnd
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
Edited by XxXGoD

Share this post


Link to post
Share on other sites
bogQ

Do
         Sleep(10)
    Until Not _IsPressed("13")


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites
Hyflex

Do
         Sleep(10)
    Until Not _IsPressed("13")

It automatically restarts my scripts... I must be doing something wrong with that bit of code... Edited by XxXGoD

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
Sign in to follow this  

×