Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] Find color on screen | Good for beginner bots [VB.Net]
#1
Finding and Clicking a color on you Screen
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 Tongue 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
This ends our try. With it is a catch, meaning it will come up with the
error msgbox saying the color cannot be found.

[Image: 49026587.png]
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 Smile
Hope i helped some people Smile
[Image: blanktemplate.png]
Reply


Messages In This Thread
[Tut] Find color on screen | Good for beginner bots [VB.Net] - by mmki - 08-11-2010, 06:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to hook the keyboard. [VB.NET] [TuT] Vorfin 92 54,743 09-23-2019, 11:55 AM
Last Post: Jamimartin
  VB.NET Port Scanner [TUT] Fragma 30 12,683 11-27-2012, 11:26 PM
Last Post: ƃu∀ ıʞƃu∀
  [TUT] MD5 Encrypter & Finder [VB.NET] Fragma 12 6,963 11-25-2012, 10:36 PM
Last Post: ƃu∀ ıʞƃu∀
  [TUT] How to make a simple WebBrowser in VB 2010! [TUT] - [ Pictures] Statics 95 55,624 10-07-2012, 06:56 AM
Last Post: a99
  [VB.Net][SRC]ProgressBar Color HF~Legend 14 6,809 09-08-2012, 04:18 PM
Last Post: spesificrelax

Forum Jump:


Users browsing this thread: 1 Guest(s)