Jump to content
Sign in to follow this  
Fretwise

Cutting CPU usage from simple loop?

Recommended Posts

I have a extremely simple program used for automating basic actions within a program. The problem is, due to it being executed within a while loop its causing the cpu usage to go to 50% just for the process, thus making the original process that it's mimicking actions for having slow down issues. Is there a better way to do this without it using all the cpu? Thanks in advance :blink:

$Run = 0
$We = 1

;Global $Paused

HotKeySet("e", "CON") 
HotKeySet("d", "SMI") 
HotKeySet("f", "SYN") 
HotKeySet("g", "TEL") 
HotKeySet("/", "Quit") 
HotKeySet("'", "Pause")

While 1
    If $Run = 1 Then
        If $We = 1 Then         
            Send("{F6}")
            Send("{F2}")
            $Run = 0
        ElseIf $We <> 1 Then
            Send("w")
            Send("e")
            $We = 1
        EndIf
    EndIf
    
    If $Run = 2 Then
        If $We = 2 Then
            Send("{F3}")
            Send("{F4}")
            $Run = 0
        ElseIf $We <> 2 Then
            Send("w")
            Send("d")
            $We = 2
       EndIf
    EndIf
    
    
    If $Run = 3 Then
        If $We = 1 Then
            Send("{F5}")
            Send("{F2}")
            $Run = 0
        ElseIf $We <> 1 Then
            Send("w")
            Send("f")
            $We = 1
        EndIf
    EndIf
    
    If $Run = 4 Then
        If $We = 2 Then
            Send("{F1}")
            MouseClick("Right")
            Send("{F3}")
            Send("{F4}")
            $Run = 0
        ElseIf $We <> 2 Then
            Send("w")
            Send("g")
            $We = 2
        EndIf
    EndIf
    
WEnd 

Func CON()     
    $Run = 1 
EndFunc 

Func SMI()     
    $Run = 2
EndFunc 

Func SYN()
    $Run = 3
EndFunc

Func TEL()
    $Run = 4
EndFunc

;Func Pause()
;   Send("{ENTER}")
;    $Paused = NOT $Paused
;    While $Paused
;        sleep(100)
;        ToolTip('Script is "Paused"',200,200)
;    WEnd
;    ToolTip("")
;EndFunc

Func Quit()     
    Exit 
EndFunc

Share this post


Link to post
Share on other sites

Thanks, I was almost positive a sleep or waiting for an input would have done the trick but wasnt quite sure in autoit. Thanks for the help :blink:

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...