Sign in to follow this  
Followers 0
MasonMill

Mouse clicking on a color that apears

14 posts in this topic

Hi guys,

How do I go about this? Its using pixelsearch. If a color appears, I want to hold the mouse down on it. I know the mouse commands, I just don't know how to go about the If and Thens to coordinate the mouse clicking when the color appears. Any suggestions? Thanks!

Share this post


Link to post
Share on other sites



Hi guys,

How do I go about this? Its using pixelsearch. If a color appears, I want to hold the mouse down on it. I know the mouse commands, I just don't know how to go about the If and Thens to coordinate the mouse clicking when the color appears. Any suggestions? Thanks!

Can't really explain this without giving you all the code or seeing what you've tried...

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

Well like I don't even know what kind of command to use to make the mouse cursor land on that color when it appears. For example in a message box, if someone messages me the tab turns red. How do I go about clicking the mouse on that red box when it turns red? I know how to set pixel search up to recognize that it does, so I can give it a coord to click somewhere that i designate but the tab might appear further down. In that case id like the cursor to click there. How would i go about doing that?

Share this post


Link to post
Share on other sites

Here's how you can go about it:

Define your x and y co-ordinates in $x and $y.

If PixelGetColor($x,$y)=0xff0000 Then
     MouseClick("left",$x,$y)
EndIf

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

The problem I see with this,if I'm understanding you right, is that say in the case of the tabs on the massage box, the tabs pop up in random spots. So is there way, more or less, you could pixelsearch(x,y,x,y) and where ever the red tab pops up that is where the cursor clicks? The way I understand yours to work is if the color at that coordinate turns red then it clicks at that same coordinate. What I would like the function to do is click where ever in that search area it does turn red because it might happen at random locations.

Share this post


Link to post
Share on other sites

Does anyone else know how to go about doing this?

Share this post


Link to post
Share on other sites

I am very familiar with pixhow del search, that is not the problem I am having. The problem is pixelsearch tells me that the color is there but what function do I use to get the cursor to click at the location where the color appears?

Share this post


Link to post
Share on other sites

$CoOrd = PixelSearch(30, 30,1024, 768, 0xff0000)   ; Looks for colour 0xff0000.
If Not @error Then ;If it exists then
MouseClick("Left", $Coord2[0], $Coord2[1], 1, 0) ;Clicks the first instance of that colour
else
MsgBox(0,"!","Could not find colur")
EndIf

Share this post


Link to post
Share on other sites

Awesome! thanks!

Share this post


Link to post
Share on other sites

$CoOrd = PixelSearch(30, 30,1024, 768, 0xff0000)   ; Looks for colour 0xff0000.
If Not @error Then ;If it exists then
MouseClick("Left", $Coord2[0], $Coord2[1], 1, 0) ;Clicks the first instance of that colour
else
MsgBox(0,"!","Could not find colur")
EndIf

I went home and looked at your code, how does it know where the color popped up? Does this code not just see that there is the color I'm looking for and I designate where to click? I am trying to make it click on that location that the color appears. Is this possible?

Share this post


Link to post
Share on other sites

I went home and looked at your code, how does it know where the color popped up? Does this code not just see that there is the color I'm looking for and I designate where to click? I am trying to make it click on that location that the color appears. Is this possible?

From the help file on pixelsearch:

Return Value

Success: Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)

Failure: Sets @error to 1 if color is not found.

PixelSearch does not return a true or false that it found the color it returns the coordinates at which if found the color.


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

From the help file on pixelsearch:

Return Value

Success: Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)

Failure: Sets @error to 1 if color is not found.

PixelSearch does not return a true or false that it found the color it returns the coordinates at which if found the color.

that's what I'm missing! Thanks!

Share this post


Link to post
Share on other sites

PixelSearch outputs a two element array of where the designated colour was found, in this instance $coOrd[0] being x and $coOrd[1] being y

These variables can be used in place of putting a specific X and Y coordinate in the MouseClick command, the outcome being the script will perform a left mouse click where the colour was found

Also that script will run an error, here's a minor correction

$CoOrd = PixelSearch(30, 30,1024, 768, 0xff0000)   ; Looks for colour 0xff0000.
If Not @error Then ;If it exists then
MouseClick("Left", $CoOrd[0], $CoOrd[1], 1, 0) ;Clicks the first instance of that colour
else
MsgBox(0,"!","Could not find colur")
EndIf

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