Results 1 to 9 of 9

Thread: Move mouse to color??

  1. #1
    New Member
    Join Date
    Mar 06
    Posts
    3

    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

  2. #2
    Member
    Join Date
    Nov 05
    Location
    California
    Posts
    41

    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.....

  3. #3
    New Member
    Join Date
    Mar 06
    Posts
    3

    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

  4. #4
    Member
    Join Date
    Nov 05
    Location
    California
    Posts
    41

    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:
    1. Public Class CaptureScreen
    2.     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
    3.  
    4.     Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
    5.  
    6.     Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
    7.  
    8.     Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
    9.  
    10.     Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
    11.  
    12.     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
    13.  
    14.     Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
    15.  
    16.     Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
    17.  
    18.     Const SRCCOPY As Integer = &HCC0020
    19.  
    20.  
    21.  
    22.  
    23.     Public Shared Function GetScreen()
    24.         Dim oBackground As Bitmap
    25.         Dim FW, FH As Integer
    26.         Dim hSDC, hMDC As Integer
    27.         Dim hBMP, hBMPOld As Integer
    28.         Dim r As Integer
    29.  
    30.         hSDC = CreateDC("DISPLAY", "", "", "")
    31.         hMDC = CreateCompatibleDC(hSDC)
    32.  
    33.         FW = GetDeviceCaps(hSDC, 8)
    34.         FH = GetDeviceCaps(hSDC, 10)
    35.  
    36.         hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
    37.  
    38.         hBMPOld = SelectObject(hMDC, hBMP)
    39.         r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)
    40.         hBMP = SelectObject(hMDC, hBMPOld)
    41.  
    42.         r = DeleteDC(hSDC)
    43.         r = DeleteDC(hMDC)
    44.  
    45.         oBackground = Image.FromHbitmap(New IntPtr(hBMP))
    46.         DeleteObject(hBMP)
    47.         Return oBackground
    48.     End Function
    49.  
    50. End Class

  5. #5
    Member
    Join Date
    Nov 05
    Location
    California
    Posts
    41

    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:
    1. Dim SearchColor As Integer = Drawing.ColorTranslator.ToOle(Color.Black)
    2. FindColor(SearchColor)

    HERE IS THE FINDCOLOR FUNCTION::::
    It sets the mouse to the first pixel it finds with that color....
    VB Code:
    1. Private Sub FindColor(ByVal MyColor As Integer)
    2.  
    3.         Dim Spic As Bitmap
    4.         Spic = CaptureScreen.GetScreen()
    5.         'capture the screen to a image
    6.  
    7.         For i As Integer = 0 To Spic.Width - 1
    8.             For k As Integer = 0 To Spic.Height - 1
    9.                 'itterate through each pixel
    10.                 If ColorTranslator.ToOle(Spic.GetPixel(i, k)) = MyColor Then
    11.                     'if the pixel is the same color we are looking for
    12.                     Windows.Forms.Cursor.Position = New Point(i, k)
    13.                     'exit the routine to save time
    14.                     Exit Sub 'maybe get rid of this line if you want to other pixels too
    15.  
    16.                 End If
    17.             Next
    18.         Next
    19.     End Sub

    So just add the "ScreenCapture" class to your project
    Use the findcolor function to set the mouse to that pixel

    Good Luck

  6. #6
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Move mouse to color??

    EDIT: Fixed my question. tyhnx tho
    Last edited by therehere3; Sep 8th, 2012 at 11:42 PM.

  7. #7
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    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

  8. #8
    New Member
    Join Date
    Mar 06
    Posts
    3

    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.

  9. #9
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Move mouse to color??

    Quote Originally Posted by pistol View Post
    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
  •