How can I detect the left/right if the object haven't mousedown, mousemove, mouseup... event??
How can I make the mouse right click whereever it is on the screen through code?
Printable View
How can I detect the left/right if the object haven't mousedown, mousemove, mouseup... event??
How can I make the mouse right click whereever it is on the screen through code?
Im not sure if this is right, for i have not tested it myself, but done something similar at one point. You will need a timer
Sub Function Timer1_Timer()
If Button = 1 Then
'Place action here for the first mouse button....
End If
If Button = 2 Then
'Place action here for the second mouse button
End If
End Sub
Again....I havent tested it, it might have to be under a click/mouse event subform but again im not sure....
To get the Status of the Left/Right Mouse Buttons wether or not a Control has any Mouse Events, you can use the GetAsyncKeyState API in a Timer, ie.
To Click the Left/Right Mouse Button anywhere the Mouse Cursor Happens to be use the Mouse_Event API, ie.Code:Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_LBUTTON = &H1
Private Const VK_RBUTTON = &H2
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(VK_LBUTTON) Then
Caption = "Left Click"
ElseIf GetAsyncKeyState(VK_RBUTTON) Then
Caption = "Right Click"
Else
Caption = ""
End If
End Sub
Code:Private 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)
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Private Sub DoLeftClick()
Call mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&)
End Sub
Private Sub DoRightClick()
Call mouse_event(MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0&, 0&, 0&, 0&)
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Thanks