Re: Trapping 4th and 5th (back/forward) mouse button
- From: "Mike D Sutton" <EDais@xxxxxxxx>
- Date: Tue, 26 Jul 2005 09:47:51 +0100
> Is there any way to capture the back/forth buttons on Microsoft's
> IntelliMouse Explorer and Trackball? Thanks in advance.
Handle the various "XButton" window messages in your window proc. The OnXButtonMsg() handler below will handle all
three window messages:
'***
Private Enum enMouseVirtualKeys
mvkLButton = &H1
mvkRButton = &H2
mvkShift = &H4
mvkControl = &H8
mvkMButton = &H10
mvkXButton1 = &H20
mvkXButton2 = &H40
End Enum
Private Const WM_XBUTTONDOWN As Long = &H20B
Private Const WM_XBUTTONUP As Long = &H20C
Private Const WM_XBUTTONDBLCLK As Long = &H20D
Private Function OnXButtonMsg(ByVal hWnd As Long, _
ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim VKeys As Long, Button As Long
Dim X As Long, Y As Long
VKeys = LowWord(wParam)
Button = HighWord(wParam)
X = SWordToUWord(LowWord(lParam))
Y = SWordToUWord(HighWord(lParam))
Select Case uMsg
Case WM_XBUTTONDOWN: Debug.Print "XButton down - ";
Case WM_XBUTTONUP: Debug.Print "XButton up - ";
Case WM_XBUTTONDBLCLK: Debug.Print "XButton doube click - ";
End Select
Debug.Print "Virtual keys: [" & MouseVirtualKeysToString(VKeys) & _
"], Button: " & CStr(Button) & " @ " & CStr(X) & ", " & CStr(Y)
' Return API true since we handled this
OnXButtonMsg = 1
End Function
Private Function LowWord(ByVal inDWord As Long) As Integer
LowWord = inDWord And &H7FFF&
If (inDWord And &H8000&) Then LowWord = LowWord Or &H8000
End Function
Private Function HighWord(ByVal inDWord As Long) As Integer
HighWord = LowWord(((inDWord And &HFFFF0000) \ &H10000) And &HFFFF&)
End Function
Private Function SWordToUWord(ByVal inWord As Integer) As Long
SWordToUWord = inWord And &H7FFF& ' Signed to unsigned Word
If (inWord And &H8000) Then SWordToUWord = SWordToUWord Or &H8000&
End Function
Private Function MouseVirtualKeysToString( _
ByVal inFlags As enMouseVirtualKeys) As String
Dim ResStr As String
If (inFlags = 0) Then
MouseVirtualKeysToString = "[ None ]"
Else
If (inFlags And mvkShift) Then ResStr = ResStr & "Shift, "
If (inFlags And mvkControl) Then ResStr = ResStr & "Control, "
If (inFlags And mvkLButton) Then ResStr = ResStr & "Left button, "
If (inFlags And mvkRButton) Then ResStr = ResStr & "Right button, "
If (inFlags And mvkMButton) Then ResStr = ResStr & "Middle button, "
If (inFlags And mvkXButton1) Then ResStr = ResStr & "X-Button 1, "
If (inFlags And mvkXButton1) Then ResStr = ResStr & "X-Button 2, "
MouseVirtualKeysToString = Left$(ResStr, Len(ResStr) - 2)
End If
End Function
'***
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: EDais@xxxxxxxx
WWW: Http://EDais.mvps.org/
.
- References:
- VB6: Trapping 4th and 5th (back/forward) mouse button
- From: Martin A. Weinberger
- VB6: Trapping 4th and 5th (back/forward) mouse button
- Prev by Date: Re: Oracle Database and VB6
- Next by Date: Re: Oracle Database and VB6
- Previous by thread: Re: Trapping 4th and 5th (back/forward) mouse button
- Next by thread: Re: Datagrid - how to format a DataGrid column as "%" - VB6
- Index(es):