Using VB 6 to control a mouse
Hi I have made a program which allows me to use a remote control to launch programs, it reads in a unique binary code for whatever button is pressed then it uses a case statement to launch a program.
I want it to be able to control the curcor onscreen so that when I press the up button it will continue up?
are their any pre written functions to do this, I know of some but I am unsure of what to use.
Thanks for any help
Re: Using VB 6 to control a mouse
Get/SetCursorPos api's should do the job. Try something like this:
Code:
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" _
(ByVal X As Long, ByVal Y As Long) As Long
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim pt As POINTAPI
GetCursorPos pt
If Shift = 0 Then
Select Case KeyCode
Case vbKeyUp
pt.Y = pt.Y - 1
Case vbKeyDown
pt.Y = pt.Y + 1
Case vbKeyLeft
pt.X = pt.X - 1
Case vbKeyRight
pt.X = pt.X + 1
End Select
End If
SetCursorPos pt.X, pt.Y
End Sub
Re: Using VB 6 to control a mouse
thanks this looks like what I was looking for, just need to go learn how to use it :D
Re: Using VB 6 to control a mouse
This is great I ve manages to edit your code and add some off my own so whenever I push a button on a remote control across the room the cursor moves, now I just need to need to do right click and left click :D great project so far
Re: Using VB 6 to control a mouse
Try using MouseDown event handler:
Code:
Option Explicit
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
'do something
ElseIf Button = vbRightButton Then
'do something else
End If
End Sub