Sign in to follow this  
Followers 0
helpplx

Help making this more efficient

4 posts in this topic

This does what it needs to do. But whilst it runs it uses about 20+% of the cpu.. and when you press 2 to start the pixelsearch it gets even worse.

My knowledge of autoit is nonexistent so I was wondering if it's possible to make this do what it does without taking up a 5th of my cpu?

Thanks in advance.

Func _IsPressed($hexKey)

  
  Local $aR, $bO
  
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
  If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
     $bO = 1
  Else
     $bO = 0
  EndIf
  
  Return $bO
EndFunc 



$colorred = 0xEE405A
$colorgold = 0xFCFB52
$colorblue = 0x42B5F9
$color = 0xEE405A


While 1
    
      If _IsPressed('61') = 1 Then $color = $colorblue
      If _IsPressed('62') = 1 Then $color = $colorred
      If _IsPressed('63') = 1 Then $color = $colorgold
    
    
         If _IsPressed('32') = 1 Then 
          while 1
            $coord = PixelSearch(555, 928, 588, 965, $color, 40, 2)
            If IsArray($coord) = 1 Then
                send ("2")
                sleep (100)
                exitloop
            endif
        wend
        endif
        wend

Share this post


Link to post
Share on other sites

Hey, welcome to the forum, if you was to put a Sleep(100) in your main While loop it would give your cpu chance to have a breather.


GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

The reason it is using so much memory is that you are opening and closing the DLL every time _IsPressed is called - instead use DllOpen before your loop and then pass in the handle returned from that function:

Func _IsPressed($hexKey,$dll)
    Local $aR, $bO
  
  $hexKey = '0x' & $hexKey
  $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey)
  If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
     $bO = 1
  Else
     $bO = 0
  EndIf
  
  Return $bO
EndFunc 



$colorred = 0xEE405A
$colorgold = 0xFCFB52
$colorblue = 0x42B5F9
$color = 0xEE405A

$dll = DllOpen("user32.dll")
While 1
    
      If _IsPressed('61',$dll) = 1 Then $color = $colorblue
      If _IsPressed('62',$dll) = 1 Then $color = $colorred
      If _IsPressed('63',$dll) = 1 Then $color = $colorgold
    
    
         If _IsPressed('32') = 1 Then 
          while 1
            $coord = PixelSearch(555, 928, 588, 965, $color, 40, 2)
            If IsArray($coord) = 1 Then
                send ("2")
                sleep (100)
                exitloop
            endif
        wend
        endif
        wend

You may also want to replace IsArray($coord) = 1 with simply @error, as it is set to 1 if the pixelsearch fails.

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  
Followers 0