Jump to content

Moving the cursor towards a moving point until it reaches it


Recommended Posts

Hi

I'm trying to get the mouse to move to an area which contains both the red and yellow colour which I have specified. I seem to have achieved this B) but I then want to make the mouse move to this area so that when it reaches it, the cursor is directly over the point. As the area is always moving I am finding this difficult. Can someone explain to me how I would be able to start moving the mouse toward an area containing two colours and then when the area moved the mouse direction would change too. When the mouse stops moving it must be touching the area. Here's what I have so far:

$yellowlocation = PixelSearch (20, 182, 1235, 891, 0xFAD76E, 30, 2)
    $redlocation = Pixelsearch ($yellowlocation[0]-40, $yellowlocation[1]-40, $yellowlocation[0]+40, 

$yellowlocation[1]+40, 0x861505, 30, 2)

while MouseGetPos() = NOT $redlocation
    MouseMove ($redlocation[0], $redlocation[1], 12)
wend
exit

Any help would be appreciated :o

Link to comment
Share on other sites

Hi

I'm trying to get the mouse to move to an area which contains both the red and yellow colour which I have specified. I seem to have achieved this B) but I then want to make the mouse move to this area so that when it reaches it, the cursor is directly over the point. As the area is always moving I am finding this difficult. Can someone explain to me how I would be able to start moving the mouse toward an area containing two colours and then when the area moved the mouse direction would change too. When the mouse stops moving it must be touching the area. Here's what I have so far:

$yellowlocation = PixelSearch (20, 182, 1235, 891, 0xFAD76E, 30, 2)
    $redlocation = Pixelsearch ($yellowlocation[0]-40, $yellowlocation[1]-40, $yellowlocation[0]+40, 

$yellowlocation[1]+40, 0x861505, 30, 2)

while MouseGetPos() = NOT $redlocation
    MouseMove ($redlocation[0], $redlocation[1], 12)
wend
exit

Any help would be appreciated :o

It sounds like you want to track a moving target.

Redlocation will change, so you need to reevaluate it within the loop.

Try this:

HotKeySet("{ESC}", "QuitApp")
Local $redlocation, $yellowlocation, $CurLoc = MouseGetPos()

While 1
    $yellowlocation = PixelSearch(20, 182, 1235, 891, 0xFAD76E, 30, 2)
    If Not @error Then
        $redlocation = PixelSearch($yellowlocation[0] - 40, $yellowlocation[1] - 40, $yellowlocation[0] + 40, $yellowlocation[1] + 40, 0x861505, 30, 2)
        If Not @error Then
            MouseMove($redlocation[0], $redlocation[1], 12)
            $CurLoc = MouseGetPos()
        EndIf
    EndIf
WEnd

Func QuitApp()
    Exit 0
EndFunc  ;==>QuitApp

p.s. You could speed up the mouse movement by lowering the speed parameter of MouseMove.

Also, you need to check for @error in case the color isn't found within the area.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

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