Jump to content

Comparing mouse pixel


D4rk^S0ul
 Share

Recommended Posts

I am writing a program where when u press a button it starts checking pixels under ur mouse and when the pixels change like screen moves or ur mouse does it left clicks so far i been trying with this:

HotKeySet("{F4}", "loop")
HotKeySet("{F5}", "stop")

local $posi = mouseGetPos()
mouseMove($posi[0] + 1, $posi[1] + 1)
local $colour = pixelGetColor($posi[0] , $posi[1])
mouseMove($posi[0], $posi[1])
    
Func loop()
    While 1
        local $pos = mouseGetPos()
        mouseMove($pos[0] + 1, $pos[1] + 1)
        local $colour = pixelGetColor($pos[0] , $pos[1])
        mouseMove($pos[0], $pos[1])
        Sleep(100)
        If $pos = $posi Then
            
        Else
            MouseClick("Left")
        EndIf
    WEnd
EndFunc

Func stop()
    While 1
        Sleep(100)
    WEnd
EndFunc

While 1
    Sleep(100)
WEnd

But had no luck, i keep gettin errors with this code.

Can any1 help me?

Link to comment
Share on other sites

I'm sorry, I don't quite understand exactly what it is that you want this program to do. I don't get any errors when running it. Right now, it does the following:

>Store the position of the mouse cursor and the color of the pixel under it immediately

>If the user presses F4, enter a loop:

>>Store the current position and color of the pixel under the cursor

>>Wait for a tenth of a second

>>If the just-stored position is equal to the position stored at the start of the script, do nothing, otherwise click the left mouse button

>If the user presses F5, enter a loop of doing nothing

If you wanted it to do something other than that, please specify.

Link to comment
Share on other sites

I think i posted wrong code o well i got this now:

HotKeySet("{F5}", "stop")
HotKeySet("{F4}", "loop")


Func loop()
    local $posi = mouseGetPos()
    mouseMove($posi[0] + 1, $posi[1] + 1)
    local $colour = pixelGetColor($posi[0] , $posi[1])
    mouseMove($posi[0], $posi[1])
    While 1
        local $pos = mouseGetPos()
        mouseMove($pos[0] + 1, $pos[1] + 1)
        local $colour = pixelGetColor($pos[0] , $pos[1])
        mouseMove($pos[0], $pos[1])
        Sleep(100)
        If $pos = $posi Then

        Else
            MouseClick("Left")
        EndIf
    WEnd
EndFunc

Func stop()
    While 1
        Sleep(100)
    WEnd
EndFunc

While 1
    Sleep(100)
WEnd

but it clicks soon as press f4 not when mouse moves?

Edited by D4rk^S0ul
Link to comment
Share on other sites

  • Moderators

local $posi = mouseGetPos()

mouseMove($posi[0] + 1, $posi[1] + 1)

and

local $pos = mouseGetPos()

mouseMove($pos[0] + 1, $pos[1] + 1)

You've told the mouse to move 1 in the first Local of $posi and move 1 in the second declare of $pos, and only do the function "IF" if they equal each other. Your Else statement says MouseClick if they don't equal each other.

Well if you move the mouse 1 in "Y" position, they are not going to ever equal each other. Thus, you go straight to the Else "MouseClick".

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

local $posi = mouseGetPos()

mouseMove($posi[0] + 1, $posi[1] + 1)

and

local $pos = mouseGetPos()

mouseMove($pos[0] + 1, $pos[1] + 1)

You've told the mouse to move 1 in the first Local of $posi and move 1 in the second declare of $pos, and only do the function "IF" if they equal each other. Your Else statement says MouseClick if they don't equal each other.

Well if you move the mouse 1 in "Y" position, they are not going to ever equal each other. Thus, you go straight to the Else "MouseClick".

Ya i noticed that and changed it still had same problem
Link to comment
Share on other sites

  • Moderators

;) Um... what did you change?

IMHO, you should of changed the

If $pos1 = $pos 2 Then

to

If $colour_1 = $colour_2 Then (before you say anything, I know you don't have a $colour_1 or _2, but this should give you an idea).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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