hi im trying to make a promgram that will follow certian colors on my screen with the mouse is there anyway i can do that
hi im trying to make a promgram that will follow certian colors on my screen with the mouse is there anyway i can do that
Are you looking to make this program to follow a color on the programs window, or are you looking to use the whole screen....
I can think of one way to do it for the whole screen but it won't be fast...
- have a loop where it captures the whole screen to an image,
-search for the color your looking for
-get the coordnates of the pixel
-then set the mouse to that point on the screen.....
++++Some more detail of what you actually want to follow would help out...++
I am just curious what this is for.....
i need to search the hole screen and it doesnt need to be fast
and its for like a game lol
and if u can send me code ill be very happy
Here is Code to capture the whole screen...
This works for vb.net 2005....should work for vb.net 2003
VB Code:
Public Class CaptureScreen Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As Integer Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer Const SRCCOPY As Integer = &HCC0020 Public Shared Function GetScreen() Dim oBackground As Bitmap Dim FW, FH As Integer Dim hSDC, hMDC As Integer Dim hBMP, hBMPOld As Integer Dim r As Integer hSDC = CreateDC("DISPLAY", "", "", "") hMDC = CreateCompatibleDC(hSDC) FW = GetDeviceCaps(hSDC, 8) FH = GetDeviceCaps(hSDC, 10) hBMP = CreateCompatibleBitmap(hSDC, FW, FH) hBMPOld = SelectObject(hMDC, hBMP) r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376) hBMP = SelectObject(hMDC, hBMPOld) r = DeleteDC(hSDC) r = DeleteDC(hMDC) oBackground = Image.FromHbitmap(New IntPtr(hBMP)) DeleteObject(hBMP) Return oBackground End Function End Class
Here is how you would go about capturing the screen with the code above...
This is the code you would put in the event to call the find color function...
(it translates the color to ole integer...)
VB Code:
Dim SearchColor As Integer = Drawing.ColorTranslator.ToOle(Color.Black) FindColor(SearchColor)
HERE IS THE FINDCOLOR FUNCTION::::
It sets the mouse to the first pixel it finds with that color....
VB Code:
Private Sub FindColor(ByVal MyColor As Integer) Dim Spic As Bitmap Spic = CaptureScreen.GetScreen() 'capture the screen to a image For i As Integer = 0 To Spic.Width - 1 For k As Integer = 0 To Spic.Height - 1 'itterate through each pixel If ColorTranslator.ToOle(Spic.GetPixel(i, k)) = MyColor Then 'if the pixel is the same color we are looking for Windows.Forms.Cursor.Position = New Point(i, k) 'exit the routine to save time Exit Sub 'maybe get rid of this line if you want to other pixels too End If Next Next End Sub
So just add the "ScreenCapture" class to your project
Use the findcolor function to set the mouse to that pixel
Good Luck
EDIT: Fixed my question. tyhnx tho
Last edited by therehere3; Sep 8th, 2012 at 11:42 PM.
Hey wait, now thinking about it? Can i make it search inside a range? or box area? of cordinates maybe? Like 100, 100 to 500,500 then search.
Because i would love for it to be a furnction like:
FindColor(SearchColor, STARTX, STARTY, ENDX, ENDY)
So it can if STARTX = 100 and STARTY = 100 and ENDX = 500 and ENDY = 500 so it would search inside a "box" or range inside 100,100 to 500,500 for that specific "SearchColor"?
Can u help give me that code plz? That would b aweesommee![]()
I could never get this to work with vb, got it to work in java. But there is a program called AutoHotKey that does that exact thing. finds a color from point to point works very well.