在MouseDown和MouseUp里面分别监视左右键的按下和放开。MouseUp: If (Button And VbRightButton)=VbRightButton Then RightDown=False If (Button And VbLeftButton)=VBLeftButton Then LeftDown=FalseMouseDown: If (Button And VbRightButton)=VbRightButton Then RightDown=True If (Button And VbLeftButton)=VBLeftButton Then LeftDown=True If RightDown And LeftDown Then 都按下了 End If
在VB中要如何判断鼠标左右键同时按?就像踩地雷游戏中那样。 那怕你快手如快枪手杰西,在计算机的侦测下,还是不可能有左右键同时按下的情况,一般所说的两键同按,在计算机的解读,其实是先后按下左右键的意思。所以 Button参数用3(左键+右键)是一个理论上存在,实际很难在使用者操作十发生的状况。So ,试试下面这一段: Option Explicit Dim OldButton As Byte Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, _ Y As Single) If Button = 3 Then '因为两键同时按下非常人能为,所以 Print "SupperMan" '实际上和 BingGo 要执行同一程序才对 Print "Supper Man" Else If OldButton + Button = 3 Then Print "BingGo" End If OldButton = Button End If End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, _ Y As Single) OldButton = 0 End Sub http://byrenpage.myrice.com/VB/text/control/59.htm
那个程序和我的思路是一样的。只不过我把Supenmen忽略了。
Option Explicit Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private Const VK_LBUTTON = &H1 Private Const VK_RBUTTON = &H2 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim intLMouse As Integer Dim intRMouse As Integer
If (Button And VbRightButton)=VbRightButton Then RightDown=False
If (Button And VbLeftButton)=VBLeftButton Then LeftDown=FalseMouseDown:
If (Button And VbRightButton)=VbRightButton Then RightDown=True
If (Button And VbLeftButton)=VBLeftButton Then LeftDown=True
If RightDown And LeftDown Then
都按下了
End If
如何检测左右键同时按下?
在VB中要如何判断鼠标左右键同时按?就像踩地雷游戏中那样。
那怕你快手如快枪手杰西,在计算机的侦测下,还是不可能有左右键同时按下的情况,一般所说的两键同按,在计算机的解读,其实是先后按下左右键的意思。所以 Button参数用3(左键+右键)是一个理论上存在,实际很难在使用者操作十发生的状况。So ,试试下面这一段:
Option Explicit
Dim OldButton As Byte
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, _
Y As Single)
If Button = 3 Then
'因为两键同时按下非常人能为,所以 Print "SupperMan"
'实际上和 BingGo 要执行同一程序才对
Print "Supper Man"
Else
If OldButton + Button = 3 Then
Print "BingGo"
End If
OldButton = Button
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, _
Y As Single)
OldButton = 0
End Sub
http://byrenpage.myrice.com/VB/text/control/59.htm
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_LBUTTON = &H1
Private Const VK_RBUTTON = &H2
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim intLMouse As Integer
Dim intRMouse As Integer
Sleep 50 '加这个效果要好一下,两键真正同时按下的高手并不多
intLMouse = (GetAsyncKeyState(VK_LBUTTON) And &HFF00) / 2 ^ 15
intRMouse = (GetAsyncKeyState(VK_RBUTTON) And &HFF00) / 2 ^ 15
If intLMouse = -1 And intRMouse = -1 Then
MsgBox "同击"
Exit Sub
End If
If Button = 1 Then
MsgBox "左键"
End If
If Button = 2 Then
MsgBox "右键"
End If
End Sub