Jump to content

simple logic, need help


Recommended Posts

Hey, the first MouseClick works when it is finding the square position but after that it doesn't hold down the mouse on the next pixel

I want it to click the pixel and hold down the mouse basically, I'm not sure if this is completely wrong or I need to add in a mouse move?

Global $Active = 0

While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616, 3)
        If IsArray($SquarePosition) Then
            MouseClick("left", $SquarePosition[0], $SquarePosition[1], 1, 0)
            $Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
            If IsArray($Start) Then
                AutoItSetOption("MouseClickDownDelay", 2000)
            EndIf
            Sleep(10)
        EndIf
    EndIf
WEnd
Link to comment
Share on other sites

Global $Active = 0

While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616, 3)
        If IsArray($SquarePosition) Then
            MouseClick("left", $SquarePosition[0], $SquarePosition[1], 1, 0)
            $Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
            If IsArray($Start) Then
                MouseMove($SquarePosition[0], $SquarePosition[1], 0)
                MouseDown("left")
                Sleep(2000)
                MouseUp("left")
            EndIf
            Sleep(10)
        EndIf
    EndIf
WEnd

Link to comment
Share on other sites

I have this now, but it failed to compile

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
HotKeySet("{a}", "_Start")
HotKeySet("{s}", "_Pause")
HotKeySet("{d}", "_Exit")

Global $Active = 0 While 1
If $Active = 1 Then
    $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616, 3)
    If IsArray($SquarePosition) Then
        MouseClick("left", $SquarePosition[0], $SquarePosition[1], 1, 0)
        $Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
        If IsArray($Start) Then
            MouseMove($SquarePosition[0], $SquarePosition[1], 0)
            MouseDown("left")
            Sleep(2000)
            MouseUp("left")
        EndIf
        Sleep(10)
    EndIf
EndIf
;### Tidy Error: next line creates a negative tablevel.
;### Tidy Error: next line creates a negative tablevel for the line after it.
WEnd

Func _Start()
    $Active = 1
EndFunc   ;==>_Start

Func _Pause()
    $Active = 0

EndFunc   ;==>_Pause

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Ah, yeah of course, sorry that was my fault

But when I run the script, it doesn't move the mouse, after it clicks the SquarePosition, it should go to Start and hold down the mouse right? But it only does the square positions

Global $Active = 0
While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616, 3)
        If IsArray($SquarePosition) Then
            MouseClick("left", $SquarePosition[0], $SquarePosition[1], 1, 0)
            $Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
            If IsArray($Start) Then
                MouseMove($Start[0], $Start[1], 0)
                MouseDown("left")
                Sleep(2000)
                MouseUp("left")
            EndIf
            Sleep(10)
        EndIf
    EndIf
WEnd
Link to comment
Share on other sites

So what happens if you test it by itself?

$Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
If IsArray($Start) Then
    ToolTip("PixelSearch() [0] = " & $Start[0] & "; [1] = " & $Start[1])
    MouseMove($Start[0], $Start[1], 0)
    MouseDown("left")
    Sleep(2000)
    MouseUp("left")
Else
    ToolTip("PixelSearch() failed")
EndIf

:mellow:

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

So what happens if you test it by itself?

$Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
If IsArray($Start) Then
    ToolTip("PixelSearch() [0] = " & $Start[0] & "; [1] = " & $Start[1])
    MouseMove($Start[0], $Start[1], 0)
    MouseDown("left")
    Sleep(2000)
    MouseUp("left")
Else
    ToolTip("PixelSearch() failed")
EndIf

:mellow:

that works, it clicks the pixel and holds the mouse for two seconds
Link to comment
Share on other sites

**edit**

Finally getting frustrated enough with not seeing anything wrong with the code, I opened up a photo editor started a new project, placed 2 dots (1 of each color) and used this code and it worked as expected... something is wrong with your colors or window that you are trying to interact with.

OPT("TrayIconDebug",1)
Sleep(100)
Global $Active = 1
While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616, 3)
        If IsArray($SquarePosition) Then
            MouseClick("left", $SquarePosition[0], $SquarePosition[1], 1, 0)
            $Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
            If IsArray($Start) Then
                MouseMove($Start[0], $Start[1], 0)
                MouseDown("left")
                Sleep(2000)
                MouseUp("left")
            EndIf
            Sleep(10)
        EndIf
    EndIf
WEnd
Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Is it possible that it's looping trying to find the squareposition and not moving onto the move mouse to the start position?

When I tested it individually it worked fine, only when it's together it doesn't work :S

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
HotKeySet("{a}", "_Start")
HotKeySet("{s}", "_Pause")
HotKeySet("{d}", "_Exit")

Global $Active = 0
While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616, 3)
        If IsArray($SquarePosition) Then
            MouseClick("left", $SquarePosition[0], $SquarePosition[1], 1, 0)
            $Start = PixelSearch(0, 0, 1696, 1036, 0x53DF0A)
            If IsArray($Start) Then
                MouseMove($Start[0], $Start[1], 0)
                MouseDown("left")
                Sleep(2000)
                MouseUp("left")
            EndIf
            Sleep(10)
        EndIf
    EndIf
WEnd

Func _Start()
    $Active = 1
EndFunc   ;==>_Start

Func _Pause()
    $Active = 0

EndFunc   ;==>_Pause

Func _Exit()
    Exit
EndFunc   ;==>_Exit
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...