• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Move mouse to a certain color

I would like to be able to put a color in a textbox (example #FFFFFF) and have the mouse move to that color?

Does anyone know the code to do somthing like that?
0
reggiewolf
Asked:
reggiewolf
  • 2
  • 2
1 Solution
 
jmwheelerCommented:
I'm not 100% clear on what you are trying to accomplish.  You want to enter a color in a textbox and have the mouse to that color but where is that color?  Is it a different control with a background color or the forms background color.  Please be more specific.
0
 
reggiewolfAuthor Commented:
I Am trying to find out how to move the mouse to a given Pixel. Like a given Colored Pixel. For instence lets say RED how can i get the mouse to only look for red colors on a BOX that is like 50x50 around the mouse.. how can i get the Mouse to go strait to the Red colored Pixel.
0
 
zzzzzoocCommented:
This could be a start for you.. set the form's borderstyle to 0 and try it. Reason is.. you have to get the x/y position of the PictureBox relative to the screen (to set the mouse cursor to) and caption bar sizes vary... (I think you'll need to use GetSysMetrics to get it's size)


Form1:
=========

Option Explicit

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()
    Call GotoPixel(Picture1, RGB(0, 0, 0))
End Sub
Private Sub Command2_Click()
    Call GotoPixel(Picture1, RGB(255, 255, 255))
End Sub
Private Sub Form_Load()
    Picture1.BorderStyle = 0
    Picture1.Picture = LoadPicture("c:\test.bmp")
End Sub
Private Sub GotoPixel(ByRef PicBox As PictureBox, lRGB As Long)
    Dim lPosX As Long, lPosY As Long
    Dim PicX As Long, PicY As Long
    'Get the X/Y pixel positions of the PictureBox relative to the screen
    'resolution
    PicX = (Me.Left / Screen.TwipsPerPixelX) + (PicBox.Left / Screen.TwipsPerPixelX)
    PicY = (Me.Top / Screen.TwipsPerPixelY) + (PicBox.Top / Screen.TwipsPerPixelY)
    'Loop through our PictureBox.. this searches from top to bottom of each pixel going
    'from left to right
    For lPosX = 1 To PicBox.Width
        For lPosY = 1 To PicBox.Height
            'Check the current pixel.. if it matches the one we specify.. position
            'the cursor at that location
            If GetPixel(PicBox.hdc, lPosX, lPosY) = lRGB Then
                Call SetCursorPos(PicX + lPosX, PicY + lPosY)
                Exit Sub
            End If
        Next lPosY
    Next lPosX
End Sub
0
 
reggiewolfAuthor Commented:
How would you make it realtime?
0
 
zzzzzoocCommented:
What do you mean by "realtime"? If it's in a TextBox event or Command Button event.. there's no real difference.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now