Jump to content

Help with optimizing quick program


Allen
 Share

Recommended Posts

Hey guys. I just need a wee bit of help with this code.. I made it for my company (even though I'm a little lowbie that that is lowest position of data entry--currently student in computer science), and what I try to automate is this program we use to process emails. So, in the program what is happening is, I first record the location of the "move" button into the program with the GetCoords() function, and then it sits and waits until the num1 (code 61) key or the num2 (code 62) key or the escape is pressed. When the 1 key is pressed, it moves th emouse to the "move" button and clicks, then it tabs 2 times, and presses down 1 time and presses enter. What this is doing is rerouting the email to GeneralPool2. If the user inputs the 2 key (on the numpad so the code in autoit is 62), then the mouse clicks down on the move button, then tab twice, then down TWICE this time.. and preesses enter. This highlights SPAM and sends the email to spam pool.

So if user hits num1, it goes to general pool 2, and if user hits num2 it goes to spam. At any point if the user presses escape, the program exits.

Can u help me make the code better =). The only problem I have is it uses up 100 percent of the CPU, and the screen on the LCD monitors we use at work flickers a bunch... i'd like to get the cpu to go down to as low as possible . Attached is the code =) Thank you soo much!!

Spam_Zapper___Keyboard.au3

Link to comment
Share on other sites

Hey guys. I just need a wee bit of help with this code.. I made it for my company (even though I'm a little lowbie that that is lowest position of data entry--currently student in computer science), and what I try to automate is this program we use to process emails. So, in the program what is happening is, I first record the location of the "move" button into the program with the GetCoords() function, and then it sits and waits until the num1 (code 61) key or the num2 (code 62) key or the escape is pressed. When the 1 key is pressed, it moves th emouse to the "move" button and clicks, then it tabs 2 times, and presses down 1 time and presses enter. What this is doing is rerouting the email to GeneralPool2. If the user inputs the 2 key (on the numpad so the code in autoit is 62), then the mouse clicks down on the move button, then tab twice, then down TWICE this time.. and preesses enter. This highlights SPAM and sends the email to spam pool.

So if user hits num1, it goes to general pool 2, and if user hits num2 it goes to spam. At any point if the user presses escape, the program exits.

Can u help me make the code better =). The only problem I have is it uses up 100 percent of the CPU, and the screen on the LCD monitors we use at work flickers a bunch... i'd like to get the cpu to go down to as low as possible . Attached is the code =) Thank you soo much!!

Cleaned up by removal of commented out code, adding Sleep() per JaySquared, and Tidy:

#Include <Misc.au3>

Welcome()
$MoveButton = GetCoords("'Move'", 20)
ToolTip("")

DoRoutines($MoveButton)


Func Esc()
    If _IsPressed("1B") Then
        $Begin = TimerInit()
        Do
            $Cursor = MouseGetPos()
            ToolTip(" Program Terminated ", $Cursor[0] + 20, $Cursor[1] + 20)
            $Dif = TimerDiff($Begin)
        Until ($Dif > 1000)
        Exit
    EndIf
EndFunc   ;==>Esc

Func Welcome()
    $Begin = TimerInit()
    $s_hexKey = 20 ;spacebar
    
    Do
        $Cursor = MouseGetPos()
        ToolTip(" Welcome to Spam Zapper :] ", $Cursor[0] + 20, $Cursor[1] + 20)
        $Status = _IsPressed($s_hexKey)
        $Dif = TimerDiff($Begin)
        Esc()
    Until ($Dif > 3000 Or $Status == 1)
    
    If ($Status <> 1 And $Dif > 3000) Then
        Do
            $Cursor = MouseGetPos()
            ToolTip("Make 'egain' the active window" & @CRLF & "Press <spacebar>", $Cursor[0] + 20, $Cursor[1] + 20)
            $Status = _IsPressed($s_hexKey)
            Esc()
        Until ($Status == 1)
    EndIf
EndFunc   ;==>Welcome

Func GetCoords(Const $String, $Key)
    $Begin = TimerInit()
    $s_hexKey = $Key
    
    Do
        $Cursor = MouseGetPos()
        ToolTip("Hover over " & $String & @CRLF & "<space>" & @CRLF & "(" & $Cursor[0] & "," & $Cursor[1] & ")", $Cursor[0] + 20, $Cursor[1] + 20)
        
        Esc()
        
        $Dif = TimerDiff($Begin)
        If ($Dif > 300) Then
            $Status = _IsPressed($s_hexKey)
        Else
            $Status = 0
        EndIf
    Until ($Status == 1)
    
    Return ($Cursor)
EndFunc   ;==>GetCoords

Func DoRoutines(Const $MoveButton)
    $Begin = TimerInit()
    
    While 1
        $Dif = TimerDiff($Begin)
        If ($Dif > 25) Then
            $Begin = TimerInit()
            
            Esc()
            
            $Num1 = 0
            If (_IsPressed(61)) Then
                $Num1 = 1
            EndIf
            
            $Num2 = 0
            If (_IsPressed(62)) Then
                $Num2 = 1
            EndIf
            
            If ($Num1) Then
                MouseClick("left", $MoveButton[0], $MoveButton[1], 3, 0)
                Sleep(400)
                Send("{TAB 2}")
                Send("{DOWN 1}")
                Send("{ENTER}")
            EndIf
            
            If ($Num2) Then
                MouseClick("left", $MoveButton[0], $MoveButton[1], 3, 0)
                Sleep(400)
                Send("{TAB 2}")
                Send("{DOWN 2}")
                Send("{ENTER}")
            EndIf
        EndIf
        Sleep(100) ; <=== Delay to reduce CPU load
    WEnd
EndFunc   ;==>DoRoutines

One thing to consider for v2 of your script would be HotKeySet() for responding to the user button actions. Would probably shorten and simplify...

:)

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...