I have been trying to find a way to move the mouse using VB.NET programming, I have succeded, It took a while, but I finally found how to do it. Now the problem lies in how to get the color of a pixel anywhere on the screen when the x y coords are specified. I can't seem to find it anywhere. I use Visual Studio 2008. "Getpixel." command does not seem to exist in it. Here is my current code.
Code:
Public Class Form1
Private Structure POINTAPI
Dim x As Long
Dim y As Long
End Structure
Private Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, ByVal lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" _
(ByVal x As Long, ByVal y As Long) As Long
Public Function SetCursorPosition(ByVal Window As Object, ByVal xPos As _
Long, ByVal yPos As Long) As Boolean
On Error GoTo errorhandler
Dim x As Long, y As Long
Dim lRet As Long
Dim lHandle As Long
Dim typPoint As POINTAPI
lHandle = Window.hwnd
x = CLng(xPos / 15)
y = CLng(yPos / 15)
typPoint.x = x
typPoint.y = y
lRet = ClientToScreen(lHandle, typPoint)
lRet = SetCursorPos(typPoint.x, typPoint.y)
SetCursorPosition = (lRet <> 0)
Exit Function
errorhandler:
SetCursorPosition = False
Exit Function
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SetCursorPos(txtX.Text, txtY.Text)
lblCurrentPs.Text = ("X = " & MousePosition.X & " And Y = " & MousePosition.Y)
End Sub
End Class