Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect simultaneous left and right mouse buttons down

Status
Not open for further replies.

garybe

Programmer
Oct 22, 2000
2
0
0
US
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

Hope this helps
Collin
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top