Jump to content

How do i move the mouse to..?


Recommended Posts

hey, im really new to all this, but ive been playing around and trying to figure things out on my own.

how can i move the cursor to find a specifically colored pixel and stay at it (to then click it)?

if anyone has any tips for me, that would be greatly appreciated! Thanks,

red

Link to comment
Share on other sites

You can approach this in one of two ways:

Move the Cursor then do a mouse down & mouse up

or use the function MouseClick.

MouseMove Syntax:

MouseMove ( x, y [, speed] )oÝ÷ Ù8^Ú¢ë'jjL¢ëR²Ö±jëh×6MouseDown ( "button" )oÝ÷ Ù«­¢+Ù5½ÕÍUÀ ÅÕ½ÐíÕÑѽ¸ÅÕ½ÐìoÝ÷ ØÊ.±à¥ÉÊ{ZÅ«­¢+Ù5½ÕÍ
±¥¬ ÅÕ½ÐíÕÑѽ¸ÅÕ½Ðìl°à°äl°±¥­Ìl°ÍÁuut¤
Link to comment
Share on other sites

Just found a perfect example from the AutoIt Help file:

; Find a pure red pixel in the range 0,0-20,300
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf


; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf

Just replace the msgbox with MouseClick~

Link to comment
Share on other sites

; Find a pure red pixel in the range 0,0-20,300

$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )

If Not @error Then

MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])

EndIf

; Find a pure red pixel or a red pixel within 10 shades variations of pure red

$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )

If Not @error Then

MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])

EndIf

I don't get the coordinates.. I've read so many examples and helps but I just don't get it.

I want my script to search for #FF0000 (red) on the whole screen of 1280x1024. I've tryed so many coords.. :)

Could someone please tell me what should I type: PixelSearch( x, x, x, x, 0xFF0000 )

Link to comment
Share on other sites

$coord = PixelSearch( 0, 0, 1280, 1024, 0xFF0000 ) 
;The first 4 numbers will define where to look. in this case a 1280 by 1024 pixel box from the top teft of your screen.
;0x000000 means it looks for the color pure red, you can find out the code for other colors using the auto it window info tool.
If Not @error Then
    MouseClick("left",$coord[0],$coord[1],1,0)
    ;does a left mouse click on the coordinates found by pixelsearch. 
EndIfoÝ÷ Ù8Z¶ÈhºW]£Z·*.Á©íbjv¥²n¶+b§îËb¢{h{º×°éò¢êkzËd{(§¶¬q«¶jënëm¢v®¶­sd÷D¶W6WBgV÷C·µW6WÒgV÷C²ÂgV÷Cµö6Æ6²gV÷C²¥vÆR 6ÆVWS ¶Ö¶W2FR67&BvBVçFÆÂFR÷F¶W2&W76VBà¥tVæ@ ¤gVæ2ö6Æ6²¢b33c¶6ö÷&BÒVÅ6V&6ÂÂ#Â#BÂdc¤bæ÷BW'&÷"FVà Ö÷W6T6Æ6²gV÷C¶ÆVgBgV÷C²Âb33c¶6ö÷&E³ÒÂb33c¶6ö÷&E³ÒÃäVæD`¤VæFgVæ

Edit: Changed color and screensize to the ones you asked for.

Edited by Tvern
Link to comment
Share on other sites

ok, ive got that all to work fine. thank you very much everyone for the help!

but.. its not working the best because there is usually a lot of places where this one colour is, and i dont really want a random one.. i dunno how to really explain that much better... :)

does anyone know anything about finding and selecting certain objects? im not sure if this is GUI stuff, but any advice would be greatly appreciated!

thanks,

red

Link to comment
Share on other sites

The PixelSearch has 4 parameters that define the rectangle area which you would like to search for the specific pixel.

$coord = PixelSearch( 0, 0, 1280, 1024, 0xFF0000 )

The first two are the (x,y) of the upper left corner of the rectangle. In your example, (0, 0) - or the very top left of the screen.

The second two are the (x,y) of the bottom right corner of the rectangle. In your example, (1280, 1024) - or the very bottom right of the screen (if you are using 1280 x 1024 resolution). If you want to make the box smaller, i.e. if there are a lot of places where the one color is and you have a better idea of where it is close to, then change the parameters.

$coord = PixelSearch( 200, 200, 250, 750, 0xFF0000 )

(200,200) to (250,750)

Would be roughly in the shape of this, consider the outer box your monitor and the inner box the pixel rectangle....

-------

(0,0)___________________________________________

|------------------------------------------------------------------------|

|------------------------------------------------------------------------|

|--------________----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|--------|----------|-----------------------------------------------------|

|------------------------------------------------------------------------|

|------------------------------------------------------------------------|

|------------------------------------------------------------------------|

|------------------------------------------------------------------------|

|__________________________________(1280, 1024)_|

I cannot believe i just did that. I sure hope this helps you understand ... lol

Edited by pacman1176
Link to comment
Share on other sites

Lol that's creative. I'd also like to add that finding the right spot becomes much easier if you can find a unique color. It might help if you could explain what it is you are trying to do, or give us a screenshot showing the pixel that needs to be clicked.

Link to comment
Share on other sites

ok... i do realize cutting down my window for the PixelSearch can help that out, and yes finding a unique pixel would i guess be the best solution, but thats pretty hard to do in a picture where one object can be made up of many different colored pixels and there are other objects of different nature in the same picture with some of the same colors.

:)

Link to comment
Share on other sites

Thankyou very much! I got it now. Now it paints over the red areas. :)

One last question:

If I want it to search from 50px around the mouse cursor how could I do that? Can't find on the help file. ;)

Link to comment
Share on other sites

Hey I got it on my own. :)

This goes offtopic, but can I change my "one last question" to: How can I pause my script so it does the following?:

When I start the script it wont do anything. But when I press Insert-button it starts to search for the color and click on it. And when I press Insert again it will stop, but not exit.

My code now is:

HotKeySet("{DEL}", "Terminate")

HotKeySet("{INS}", "Pause")

While 1

$color = PixelSearch( @DesktopWidth*.48, @DesktopHeight*.48, @DesktopWidth*.52, @DesktopHeight*.52, 10834258, 5 )

If Not @error Then

MouseClick("left", $color[0],$color[1],1,0)

EndIf

Sleep(25)

Wend

Func Pause()

Sleep(1000)

EndFunc

Func Terminate()

Exit

EndFunc

But pressing Insert does nothing.

Help, please and thanks. ;)

PS. Is there any way to edit posts?

Edit. I found the Edit button.. :S

Edited by arxa
Link to comment
Share on other sites

Hey I got it on my own. :)

This goes offtopic, but can I change my "one last question" to: How can I pause my script so it does the following?:

When I start the script it wont do anything. But when I press Insert-button it starts to search for the color and click on it. And when I press Insert again it will stop, but not exit.

My code now is:

But pressing Insert does nothing.

Help, please and thanks. ;)

PS. Is there any way to edit posts?

Edit. I found the Edit button.. :S

If what you are trying to do is making ins pause and unpause the script then you need to put the "active" part of the script in a function and make pressing "insert" call that function if it's paused. I think this should work:

HotKeySet("{DEL}", "Terminate")

_run()
Func _run()
HotKeySet("{INS}", "Pause")
While 1
$color = PixelSearch( @DesktopWidth*.48, @DesktopHeight*.48, @DesktopWidth*.52, @DesktopHeight*.52, 10834258, 5 )
If Not @error Then
MouseClick("left", $color[0],$color[1],1,0)
EndIf
Sleep(25)
Wend
EndFunc

Func Pause()
HotKeySet("{INS}", "_run")
While 1
Sleep(1000)
WEnd
EndFunc

Func Terminate()
Exit
EndFunc

What format is that color in BTW? I thought it had to be RGB in hex.

Link to comment
Share on other sites

Thanks, I'll try it right away tomorrow. :)

What format is that color in BTW? I thought it had to be RGB in hex.

I used PixelSearch Helper to learn PixelSearch and used it to look the color, so I don't really know what format it is, I'll change it to RGB just to be sure it works. ;)

Link to comment
Share on other sites

Yeah pausing works perfect, thankyou! :)

If I want it to search from 50px around the mouse cursor how could I do that? Can't find on the help file. ;)

I just noticed that it searches only in the middle of the screen.. Stupid me.

$color = PixelSearch( @DesktopWidth*.48, @DesktopHeight*.48, @DesktopWidth*.52, @DesktopHeight*.52, 10834258, 5 )

So back to that question, how can I make it search around the mouse cursor.

PS. Is it bad posting in this thread or should I make my own?

Edited by arxa
Link to comment
Share on other sites

Yeah pausing works perfect, thankyou! :)

I just noticed that it searches only in the middle of the screen.. Stupid me.

$color = PixelSearch( @DesktopWidth*.48, @DesktopHeight*.48, @DesktopWidth*.52, @DesktopHeight*.52, 10834258, 5 )

So back to that question, how can I make it search around the mouse cursor.

PS. Is it bad posting in this thread or should I make my own?

$pos = MouseGetPos ()
$color = Pixelsearch( $pos[0]-25, $pos[1]-25, $pos[0]+25, $pos[1]+25, 10834258, 5 )

MouseGetPos will return a two-element array where $pos[0] will be the horisontal position and $pos[1] will be the vertical position.

So by going 25 pixels in every direction from those coordinates you will create a 50 pixel box to search in.

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