|
-
Mar 2nd, 2006, 07:47 PM
#1
Thread Starter
New Member
Move mouse to color??
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
-
Mar 2nd, 2006, 11:30 PM
#2
Member
Re: Move mouse to color??
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.....
-
Mar 3rd, 2006, 05:02 PM
#3
Thread Starter
New Member
Re: Move mouse to color??
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
-
Mar 4th, 2006, 01:34 PM
#4
Member
Re: Move mouse to color??
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
-
Mar 4th, 2006, 01:38 PM
#5
Member
Re: Move mouse to color??
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
-
Sep 8th, 2012, 11:36 PM
#6
Addicted Member
Re: Move mouse to color??
EDIT: Fixed my question. tyhnx tho
Last edited by therehere3; Sep 8th, 2012 at 11:42 PM.
-
Sep 8th, 2012, 11:51 PM
#7
Addicted Member
Re: Move mouse to color??
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
-
Sep 10th, 2012, 08:11 AM
#8
Thread Starter
New Member
Re: Move mouse to color??
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.
-
Sep 10th, 2012, 11:26 PM
#9
Addicted Member
Re: Move mouse to color??
 Originally Posted by pistol
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.
oh cool. but yeeahh i need this for visual basic not java sorry
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|