Sign in to follow this  
Followers 0
Skrip

Make your mouse follow a line of a certain color

8 posts in this topic

#1 ·  Posted (edited)

I have been here for years, and have never seen anybody make this. I have seen it requested/talked about. But never made.

I just did a quick mockup of a working one. It does work. Although it is a bit slow, and it will always go up and to the right (if it can). I'll make a better one tomorrow, but I would like a few other people to also take a crack at it.

$color = "0x000000"
While 1
    $pos = MouseGetPos()
    If PixelGetColor($pos[0] - 1, $pos[1]) = $color Then; Left
        MouseMove($pos[0] - 1, $pos[1])
    EndIf
    If PixelGetColor($pos[0] - 1, $pos[1] - 1) = $color Then; Upper Left
        MouseMove($pos[0] - 1, $pos[1] - 1)
    EndIf
    If PixelGetColor($pos[0], $pos[1] - 1) = $color Then; Up
        MouseMove($pos[0], $pos[1] - 1)
    EndIf
    If PixelGetColor($pos[0] + 1, $pos[1] + 1) = $color Then;Upper Right
        MouseMove($pos[0] + 1, $pos[1] + 1)
    EndIf
    If PixelGetColor($pos[0] + 1, $pos[1]) = $color Then;Right
        MouseMove($pos[0] + 1, $pos[1])
    EndIf
    If PixelGetColor($pos[0] + 1, $pos[1] - 1) = $color Then;Lower Right
        MouseMove($pos[0] + 1, $pos[1] - 1)
    EndIf
    If PixelGetColor($pos[0], $pos[1] - 1) = $color Then;Bottom
        MouseMove($pos[0], $pos[1] - 1)
    EndIf
    If PixelGetColor($pos[0], $pos[1] - 1) = $color Then;Lower Left
        MouseMove($pos[0] - 1, $pos[1] - 1)
    EndIf
WEnd

Best way to test is to open paint, make a black line going around, run the program, and place your mouse somewhere on the line.

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites



I'm intrigued, uncertain how it can be used but it's a cool toy none the less.

So intrigued in fact that I had to play too :)

I threw this together using the PixelSearch function. The mouse trace prefers to move to 0, 0 and runs a tad faster.

Enjoy >_<

Const $color = 0x000000
Local $prev = MouseGetPos()

While 1
    $pos = MouseGetPos()
    If $pos = $prev Then ContinueLoop
    
    $pix = PixelSearch($pos[0] - 2, $pos[1] - 2, $pos[0] + 3, $pos[1] + 3, $color, 0)
    
    If @error = 1 Then ContinueLoop
    
    $prev = $pos
    MouseMove($pix[0], $pix[1])
Wend

--- TTFN

Share this post


Link to post
Share on other sites

its pretty good.. but not usefull...

Share this post


Link to post
Share on other sites

I haven't got to play with this yet, but what if it recorded where your mouse is while your holding down the left click, and when you hit play it follows the path that you took while the left mouse was clicked. Make your own gui to draw the line on instead of paint. That could be pretty cool.


Giggity

Share this post


Link to post
Share on other sites

I haven't got to play with this yet, but what if it recorded where your mouse is while your holding down the left click, and when you hit play it follows the path that you took while the left mouse was clicked. Make your own GUI to draw the line on instead of paint. That could be pretty cool.

If you wanted a program to do that I would just record the mouse positions as it moved and draw a line on the screen at the same time to give the user feedback. then when the user played back the movement it would just use the stored mouse positions.

Only reason I can see a need for this script is to incorporate the logic into a robot so it can follow a line on the floor since the robot would have no way of knowing what the path was before hand and the only data available is coming from a camera.


--- TTFN

Share this post


Link to post
Share on other sites

There was a game I used to play, called linerider I think. Where you would draw a course and your sledder would ride on it, you could make jumps, and loops and all that fun stuff. That's 1 direction I see this being able to go in.


Giggity

Share this post


Link to post
Share on other sites

I know this is old but it's the newest one I found. I opened paint and drew a line and a circle. It seems to follow the line but not the circle or turns. How can this be fixed?

I'm using the code from Zinthose

Const $color = 0x000000
Local $prev = MouseGetPos()

While 1
    $pos = MouseGetPos()
    If $pos = $prev Then ContinueLoop
    
    $pix = PixelSearch($pos[0] - 2, $pos[1] - 2, $pos[0] + 3, $pos[1] + 3, $color, 0)
    
    If @error = 1 Then ContinueLoop
    
    $prev = $pos
    MouseMove($pix[0], $pix[1])
Wend

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