Click to See Complete Forum and Search --> : simulate mouse button
alienskiller
Dec 17th, 2000, 06:11 PM
how can i simulate the click of the mouse in the code????
Jerry Grant
Dec 18th, 2000, 07:30 AM
With the mouse_event API:
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 ;)
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.