08-11-2010, 06:02 AM
Finding and Clicking a color on you Screen
By MMKI
By MMKI
Hey guys
I posted this tut on HF a while ago. Thought i would post here also. Only thing i worry of is if there is a way easier way to do this
that i haven't found Please don't use the code without looking over it. Its to learn not to use.
It scans each pixel on the screen for a RGB color. In this case i'm using it to find the light red ball on a game on pool in the popular game website OMGPOP.
The color im using is 217, 59, 73 (light red)
Place a button on your form and double click it to edit its code
Code:
Dim screensize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screenshot As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenshot)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screensize)
This code takes a screenshot of the screen at sets it to full size (you will not be able to see it) Its from this invisible screenshot that the program will find the color
Next add the following
Code:
Dim pointx As Integer = 1
Dim pointy As Integer = 1
Dim looking As Boolean = True
Just declaring some integers and a boolean we are about to use. pointx
and pointy are the pixel that the program will scan for the correct colored pixel
Now add
Code:
Try
While looking = True
Dim atpoint As Color = screenshot.GetPixel(pointx, pointy)
Dim red As Color = Color.FromArgb(255, 217, 59, 73) 'light red ball colour
If atpoint = red Then
Cursor.Position = New Point(pointx, pointy)
looking = False
pointx = 1
pointy = 1
End If
pointy = pointy + 1
If pointy = My.Computer.Screen.Bounds.Height Then
pointy = 0
pointx = pointx + 1
End If
End While
This code starts at the first pixel (1, 1). Then continues to scan each pixel until
it reaches the correct colored pixel.
Dim red As Color = Color.FromArgb(255, 217, 59, 73) 'light red
It is with that line in the previous code that you choose what color you want to find. In my case light red (255, 217, 59, 73)
Next add:
Code:
Catch ex As Exception
MsgBox("Cannot find Color", , "HELP")
End Try
error msgbox saying the color cannot be found.
You can see here, kinda, that my mouse has found the color ball i selected and moved the mouse there.
http://www.hackforums.net/showthread.php?tid=232812 < This tutorial, by hackurheart, tells you how to simulate a mouse click. Which will come in handy if your trying to make a bot with this method or something.
Thanks for reading
Hope i helped some people