Results 1 to 6 of 6

Thread: ¿ Searching for a color ?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    55

    Wink ¿ Searching for a color ?

    How do I make VB search the computer screen for a certain color pixel, then have it center the mouse on it? Could I make this work while running a different program and having this run in the background???

    -Thx

    - Sk

  2. #2
    Frenzied Member numtel's Avatar
    Join Date
    Apr 2000
    Location
    CA
    Posts
    1,163
    it would probably take a while because you would have to step through every pixel on screen and then use the getpixel api call.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    55
    Well, could I have it search everytime I press a button.
    And could I make it run while running another program?

    -Thx

    - Sk

  4. #4
    Frenzied Member numtel's Avatar
    Join Date
    Apr 2000
    Location
    CA
    Posts
    1,163
    i'll make a program to do it. it will probably take 10mins or so to run it.

  5. #5
    Frenzied Member numtel's Avatar
    Join Date
    Apr 2000
    Location
    CA
    Posts
    1,163
    VB Code:
    1. 'Declaration
    2. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    3.  
    4. 'Code to check
    5. Dim CurrentPixel As Long
    6. For i = 0 To Screen.Width Step Screen.TwipsPerPixelX
    7.     For j = 0 To Screen.Height Step Screen.TwipsPerPixelY
    8.         CurrentPixel = GetPixel(0, i, j)
    9.         If RGB(192, 192, 192) = CurrentPixel Then 'replace with your color!
    10.             'do something
    11.         End If
    12.     Next j
    13. Next i

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    55
    I tried that and for some reason it didn't work...
    And I know what I put in has R:0 G:191 B:0
    Maybe it's just me, but I put this code:
    VB Code:
    1. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    2.  
    3.  
    4. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    5. If KeyCode = vbKeyL Then
    6.  
    7. Dim CurrentPixel As Long
    8. For i = 0 To Screen.Width Step Screen.TwipsPerPixelX
    9.     For j = 0 To Screen.Height Step Screen.TwipsPerPixelY
    10.         CurrentPixel = GetPixel(0, i, j)
    11.         If RGB(0, 191, 0) = CurrentPixel Then 'replace with your color!
    12.             'do something
    13.             MsgBox "x:" & i & "y:" & j
    14.             End
    15.         End If
    16.     Next j
    17. Next i
    18.  
    19.  
    20. End If
    21.  
    22. End Sub

    Thanks 4 that much

    Oh, and how do I make this work whenever I press L, even if I am in a different program?
    And what id the ''ByVal hdc As Long'' mean?


    - Thank you very much 4 helping me

    - Sk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width