Using VB 6 to control a mouse-VBForums
Results 1 to 5 of 5

Thread: Using VB 6 to control a mouse

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    6

    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

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,133

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    6

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    6

    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 great project so far

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,133

    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

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.