Jump to content

Is there any way to accelerate PixelGetColor?


Recommended Posts

#include <Misc.au3>
#include <FastFind.au3>
#include <WinAPI.au3>
#include <APIConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

$color = 16765255 ; 색깔#
$colorhex = 0xffd247
$coord1 = 763
$coord2 = 841
$coord3 = 919
$coord4 = 997
$count = 0

While 1

If $count = 0 Then
$mouse = MouseGetPos()
EndIf

$button4 = PixelGetColor($coord4, 606)
If $button4 = $color Then
MouseClick("left", $coord4 + 30, 625, 1, 1)
$count += 1
EndIf

$button4 = PixelGetColor($coord4, 606)
$button3 = PixelGetColor($coord3, 606)
If $button4 <> $color And $button3 = $color Then
MouseClick("left", $coord3 + 30, 625, 1, 1)
$count += 1
EndIf

$button4 = PixelGetColor($coord4, 606)
$button3 = PixelGetColor($coord3, 606)
$button2 = PixelGetColor($coord2, 606)
If $button4 <> $color And $button3 <> $color And $button2 = $color Then
MouseClick("left", $coord2 + 30, 625, 1, 1)
$count += 1
EndIf

$button4 = PixelGetColor($coord4, 606)
$button3 = PixelGetColor($coord3, 606)
$button2 = PixelGetColor($coord2, 606)
$button1 = PixelGetColor($coord1, 606)
If $button4 <> $color And $button3 <> $color And $button2 <> $color And $button1 = $color Then
MouseClick("left", $coord1 + 30, 625, 1, 1)
$count += 1
EndIf

WEnd

There are four buttons that light up in certain conditions, and I am trying to click them as fast as I can.

 

Also, I MUST press Button 4 before Button 3, 3 before 2, and 2 before 1. Which is the reason I wrote it like:

$button4 = PixelGetColor($coord4, 606)
$button3 = PixelGetColor($coord3, 606)
$button2 = PixelGetColor($coord2, 606)
$button1 = PixelGetColor($coord1, 606)
If $button4 <> $color And $button3 <> $color And $button2 <> $color And $button1 = $color Then...

 

I am currently using PixelGetColor, but I'm not sure if this is the best way to do this process loop.

Is there any faster function which does the same thing as PixelGetColor?

Or possibly any way to accelerate the process..?

 

+ If anyone can help compress the coding neatly, It'll be great, too.

Edited by JJ1122
Link to post
Share on other sites

Remove useless call to PixelGetColor :

$color = 16765255
$colorhex = "0x" & Hex($color)
$coord1 = 763
$coord2 = 841
$coord3 = 919
$coord4 = 997
$count = 0

While 1

  If $count = 0 Then $mouse = MouseGetPos()
  Sleep (10) ; to reduce CPU overload

  $button4 = PixelGetColor($coord4, 606)
  If $button4 = $color Then
    MouseClick("left", $coord4 + 30, 625, 1, 0) ; use fastest click
    $count += 1
    ContinueLoop
  EndIf

  $button3 = PixelGetColor($coord3, 606)
  If $button3 = $color Then
    MouseClick("left", $coord3 + 30, 625, 1, 0) ; use fastest click
    $count += 1
    ContinueLoop
  EndIf

  $button2 = PixelGetColor($coord2, 606)
  If $button2 = $color Then
    MouseClick("left", $coord2 + 30, 625, 1, 0) ; use fastest click
    $count += 1
    ContinueLoop
  EndIf

  $button1 = PixelGetColor($coord1, 606)
  If $button1 = $color Then
    MouseClick("left", $coord1 + 30, 625, 1, 0) ; use fastest click
    $count += 1
  EndIf

WEnd

 

Link to post
Share on other sites

You may need to set these opt parameters to higher than 10 milliseconds:

MouseClickDelay Alters the length of the brief pause in between mouse clicks.
Time in milliseconds to pause (default=10).
MouseClickDownDelay Alters the length a click is held down before release.
Time in milliseconds to pause (default=10).

Code hard, but don’t hard code...

Link to post
Share on other sites
17 minutes ago, JockoDundee said:

You may need to set these opt parameters to higher than 10 milliseconds:

MouseClickDelay Alters the length of the brief pause in between mouse clicks.
Time in milliseconds to pause (default=10).
MouseClickDownDelay Alters the length a click is held down before release.
Time in milliseconds to pause (default=10).

Will it stabilize the clicks? What happens if I make them 0?

Link to post
Share on other sites

If changes happen really really fast, then there is no way to ensure that while you are clicking 3 that 4 should be clicked before.  It is just a question of nano seconds, and then you are doom to fail.  Ensuring a true solution will require more info and a decisive replicable environment.

Link to post
Share on other sites
2 hours ago, JJ1122 said:

Will it stabilize the clicks? What happens if I make them 0?

The control may need time to respond to the click message.

But wait a second, do the buttons change color when clicked?
If you are relying on that fact to know whether to click or not, and you don’t give any delay after clicking, you will end up with all sorts of crazy results.  For instance, you could easily click a button twice because it has not been redrawn yet.

I’m with @Nine, more info on what exactly this “electric circuit management” app is doing is needed, and why sub-second response is critical.

The idea would be NOT to make them 0, but to make them greater than 10, the default.  10 milliseconds is really short, trust me a normal app can spare 100ms without any significant delay.

Edited by JockoDundee
Added part about making it 0

Code hard, but don’t hard code...

Link to post
Share on other sites
  • 2 weeks later...
On 10/22/2020 at 6:36 AM, Nine said:

If changes happen really really fast, then there is no way to ensure that while you are clicking 3 that 4 should be clicked before.  It is just a question of nano seconds, and then you are doom to fail.  Ensuring a true solution will require more info and a decisive replicable environment.

 

On 10/22/2020 at 7:47 AM, JockoDundee said:

The control may need time to respond to the click message.

But wait a second, do the buttons change color when clicked?
If you are relying on that fact to know whether to click or not, and you don’t give any delay after clicking, you will end up with all sorts of crazy results.  For instance, you could easily click a button twice because it has not been redrawn yet.

I’m with @Nine, more info on what exactly this “electric circuit management” app is doing is needed, and why sub-second response is critical.

The idea would be NOT to make them 0, but to make them greater than 10, the default.  10 milliseconds is really short, trust me a normal app can spare 100ms without any significant delay.

Thank you for the suggestions! Guess I'll need to think more about how to solve this myself/

Getting close tho.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...