I'm trying to allow users to use a simultaneous left and right button click to indicate certain conditions. I've seen it done (minesweeper comes to mine) but I am unable to come up with any code or control to allow me to do this. [sig][/sig]
Here is a way to detect both mouse buttons being pushed useing two Timer controls
Option Explicit
Dim blnLeft As Boolean ' Left button pushed Dim blnRight As Boolean ' Right button pushed Dim blnBoth As Boolean ' Both buttons pushed
I used a Command button as the Control that I wanted to monitor
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = True
If Button = vbLeftButton Then blnLeft = True
If Button = vbRightButton Then blnRight = True
End Sub
Private Sub Timer1_Timer()
'set for 200ms If blnLeft And blnRight Then
blnBoth = True
End If
blnLeft = False
blnRight = False
Timer1.Enabled = False
End Sub
Private Sub Timer2_Timer()
'Timer two is allways enabled and set for 200ms If blnBoth Then
You would put the code here to react to the Both buttons being clicked MsgBox "Both buttons pushed"
blnBoth = False
End If
End Sub
Not the prettest code, but it works you could do some experimenting to determine the altimate Timer intervals
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.