|
-
Jun 30th, 2008, 03:11 PM
#1
[RESOLVED] Windows Messages - Mouse Forward & Backward buttons
Anyone know what Windows Messages are for the forward and backward mouse buttons, for example I know how to get the mouse wheel...
Code:
If Msg = WM_MOUSEWHEEL Then
Rotation = wParam / 65536
End If
... but not sure what the code would be for forward and backward buttons (on mouse button up),
So far I've got this but not sure its correct or not. ?
Code:
If Msg = 524 Then '&H20C
If wParam = 131072 Then '&H20000
ForwardButtonUp = True
ElseIf wParam = 65536 Then '&H10000
BackwardButtonUp = True
End If
End If
-
Jun 30th, 2008, 05:31 PM
#2
Re: Windows Messages - Mouse Forward & Backward buttons
Here's a nice collection of mouse related messages:
Code:
Private Const WM_MOUSEWHEEL = &H20A
Private Const WM_MOUSEACTIVATE As Integer = &H21
Private Const WM_MOUSEMOVE As Integer = &H200
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_LBUTTONUP As Integer = &H202
Private Const WM_LBUTTONDBLCLK As Integer = &H203
Private Const WM_RBUTTONDOWN As Integer = &H204
Private Const WM_RBUTTONUP As Integer = &H205
Private Const WM_RBUTTONDBLCLK As Integer = &H206
Private Const WM_MBUTTONDOWN As Integer = &H207
Private Const WM_MBUTTONUP As Integer = &H208
Private Const WM_MBUTTONDBLCLK As Integer = &H209
Private Const WM_XBUTTONDOWN As Integer = &H20B
Private Const WM_XBUTTONUP As Integer = &H20C
Private Const WM_XBUTTONDBLCLK As Integer = &H20D
The buttons you are interested in fall under "XButton".
Just like with the L/M/R buttons, the value is passed via wParam, eg:
Code:
Dim lngMouseButtons As Long
If Msg = WM_XBUTTONUP Then
lngMouseButtons = wParam And 65535
...
End If
The value will be one or more of the following:
1 = Left button
2 = Right button
16 = Middle button
32 = 'Back' button
64 = 'Forward' button Alternatively, you can check wParam / 65536 , which returns 1 (back) or 2 (forward) or 3 (both).
In either case, I would expect the value of any additional buttons (if there are mice with more than 5!) to be double the previous button.
As values can be added together if multiple buttons are pressed, use bit-masking to check for a specific value, eg:
Code:
If lngMouseButtons And 32 Then
BackwardButtonUp = True
End If
-
Jun 30th, 2008, 06:28 PM
#3
Re: Windows Messages - Mouse Forward & Backward buttons
Thanks Si, but I must not be following your instructions correctly, for mouse up lngMouseButtons is 0 no matter what button I press in the code below.
Code:
If Msg = WM_XBUTTONUP Then
lngMouseButtons = wParam And 65535
Debug.Print "Mouse Button Up "; lngMouseButtons ' < Returns 0
If lngMouseButtons And 32 Then
Debug.Print "Back button"
ElseIf lngMouseButtons And 64 Then
Debug.Print "Forward button"
End If
End If
-
Jul 1st, 2008, 03:27 AM
#4
Re: Windows Messages - Mouse Forward & Backward buttons
Ah.. I'd been testing with MouseDown, and it had worked as I said - but after a silly edit by me the IDE crashed, and at that time of night I didn't bother to restart it.
It seems that you only get the current state of the buttons, so using that you'd need a boolean variable per button, to remember the previous state.. however there is another way, which is to check wParam / 65536 as that returns the button which caused the event - 1 for 'back', and 2 for 'forward' (tested properly this time!).
-
Jul 1st, 2008, 05:20 AM
#5
Re: Windows Messages - Mouse Forward & Backward buttons
Was skimming thru some MSDN stuff, anyway this seems to work under XP which is all I care about.
Code:
Private Const XBUTTON1 = &H1
Private Const XBUTTON2 = &H2
'
'
If Msg = WM_XBUTTONUP Then
lngMouseButtons = wParam / 65535
If lngMouseButtons = XBUTTON1 Then
Debug.Print "Back Up"
ElseIf lngMouseButtons = XBUTTON2 Then
Debug.Print "Forward Up"
End If
End If
If Msg = WM_XBUTTONDOWN Then
lngMouseButtons = wParam / 65535
If lngMouseButtons = XBUTTON1 Then
Debug.Print "Back Down"
ElseIf lngMouseButtons = XBUTTON2 Then
Debug.Print "Forward Down"
End If
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|