Click to See Complete Forum and Search --> : mouse buttons
Topbat
Jun 28th, 2000, 11:14 AM
Hi, How can I control the mouse buttons?? like I want to "click" the left button, but i didn't actually touch the mouse. Not just get info from the button, but also be able to control them.
terebi
Jun 28th, 2000, 01:10 PM
UMM...
You could use the API mouse_event function to create a left click event.
E.g
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
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 sub LeftClick()
mouse_event MOUSEEVENTF_LEFTDOWN, 0&, 0&, 0&, 0&
mouse_event MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&
end sub
To create a click event
You can also use the SendMessage API.
Code for a module.
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_LBUTTONDBLCLK = &H203 ' Left Button Double Clicked
Public Const WM_LBUTTONDOWN = &H201 ' Left Button Down
Public Const WM_LBUTTONUP = &H202 ' Left Button Up
Public Const WM_RBUTTONDBLCLK = &H206 ' Right Button Double Clicked
Public Const WM_RBUTTONDOWN = &H204 ' Right Button Down
Public Const WM_RBUTTONUP = &H205 ' Right Button Up
Make 2 CommandButton's on your Form and put the following code in it.
Private Sub Command1_Click()
' Set a Message to Command2 with the Leftbutton Down
retval = SendMessage(Command2.hwnd, WM_LBUTTONDOWN, CLng(0), CLng(0))
End Sub
Private Sub Command2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' You you press Command1, it should trigger this event
End
End Sub
Now, when you press Command1, the program will end, as if you pressed Command2.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.