Results 1 to 3 of 3

Thread: simulate mouse button

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Posts
    2

    Question

    how can i simulate the click of the mouse in the code????

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    With the mouse_event API:

    Code:
        
    Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags _
            As Long, ByVal dx As Long, ByVal dy As Long, _
            ByVal cButtons As Long, ByVal dwExtraInfo As Long)
            
        Public Const MOUSEEVENTF_ABSOLUTE = &H8000 '  absolute move
        Public Const MOUSEEVENTF_LEFTDOWN = &H2 '  left button down
        Public Const MOUSEEVENTF_LEFTUP = &H4 '  left button up
        Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 '  middle button down
        Public Const MOUSEEVENTF_MIDDLEUP = &H40 '  middle button up
        Public Const MOUSEEVENTF_MOVE = &H1 '  mouse move
        Public Const MOUSEEVENTF_RIGHTDOWN = &H8 '  right button down
        Public Const MOUSEEVENTF_RIGHTUP = &H10 '  right button up
    
        '// Move the mouse
        Call mouse_event( _
                         MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, _
                         myX, _
                         myY, _
                         0, _
                         0 _
                         )
    
       '// Left Click the mouse.
        Call mouse_event( _
                         MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTDOWN, _
                         myX, _
                         myY, _
                         0, _
                         0 _
                         )
    
        '// Lift the mouse button
        Call mouse_event( _
                         MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTUP, _
                         myX, _
                         myY, _
                         0, _
                         0 _
                         )
    Hope this helps
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3
    Guest
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const MK_LBUTTON = &H1
    
    Private Sub Command1_Click()
        PostMessage MyHwnd, WM_LBUTTONDOWN, MK_LBUTTON, 0
        PostMessage MyHwnd, WM_LBUTTONUP, MK_LBUTTON, 0
    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
  •  



Click Here to Expand Forum to Full Width