Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUGFIX: correct handling of XButton wParam messages for auxiliary mou…

  • Loading branch information...
commit 8a46bd351a058d8f7faad4260c891e50083e69b5 1 parent e632e26
@jeske authored
View
32 Source/OpenTK/Platform/Windows/API.cs
@@ -3531,37 +3531,55 @@ internal enum VirtualKeys : short
#region MouseKeys
/// <summary>
- /// Enumerates available mouse keys (suitable for use in WM_MOUSEMOVE messages).
+ /// Enumerates flag bits for which mouse-buttons are held down during WM_MOUSEMOVE, WM_XBUTTONDOWN, and others..
/// </summary>
+ [Flags]
enum MouseKeys
{
// Summary:
- // No mouse button was pressed.
+ // No mouse button is held.
None = 0,
//
// Summary:
- // The left mouse button was pressed.
+ // The left mouse button is held.
Left = 0x0001,
//
// Summary:
- // The right mouse button was pressed.
+ // The right mouse button is held.
Right = 0x0002,
//
// Summary:
- // The middle mouse button was pressed.
+ // The middle mouse button is held.
Middle = 0x0010,
//
// Summary:
- // The first XButton was pressed.
+ // The first XButton is held.
XButton1 = 0x0020,
//
// Summary:
- // The second XButton was pressed.
+ // The second XButton is held.
XButton2 = 0x0040,
}
#endregion
+ #region MouseXButtonHIWORD
+
+ /// <summary>
+ /// Paramaters sent in wParam HIWORD of WM_XBUTTONDOWN, WM_XBUTTONUP
+ ///
+ /// See:
+ /// http://msdn.microsoft.com/en-us/library/windows/desktop/ms646245(v=vs.85).aspx
+ /// </summary>
+
+ enum MouseXButtonHIWORD
+ {
+ XButton1 = 1,
+ XButton2 = 2,
+ }
+
+ #endregion
+
#region QueueStatusFlags
/// \internal
View
29 Source/OpenTK/Platform/Windows/WinGLNative.cs
@@ -152,6 +152,29 @@ public WinGLNative(int x, int y, int width, int height, string title, GameWindow
#region WindowProcedure
+ /// <summary>
+ /// Decode the WM_XBUTTONDOWN, WM_XBUTTONUP paramaters.
+ ///
+ /// See:
+ /// http://msdn.microsoft.com/en-us/library/windows/desktop/ms646245(v=vs.85).aspx
+ /// </summary>
+ /// <param name="wParam"></param>
+ /// <returns></returns>
+ private static MouseButton GET_XBUTTON_WPARAM(Int32 wParam) {
+ Int32 wParam_HIWORD = (wParam >> 16) & 0xFFFF;
+ switch ((MouseXButtonHIWORD)wParam_HIWORD) {
+ case MouseXButtonHIWORD.XButton1:
+ return MouseButton.Button1;
+ case MouseXButtonHIWORD.XButton2:
+ return MouseButton.Button2;
+
+ // Only two buttons come through this API, so we should never see this
+ // Need to switch to DirectInput to get more buttons.
+ default:
+ return MouseButton.Button3;
+ }
+ }
+
IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
{
switch (message)
@@ -333,8 +356,7 @@ IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntP
case WindowMessage.XBUTTONDOWN:
Functions.SetCapture(window.WindowHandle);
- mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) !=
- (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true;
+ mouse[GET_XBUTTON_WPARAM(wParam.ToInt32())] = true;
break;
case WindowMessage.LBUTTONUP:
@@ -354,8 +376,7 @@ IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntP
case WindowMessage.XBUTTONUP:
Functions.ReleaseCapture();
- mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) !=
- (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false;
+ mouse[GET_XBUTTON_WPARAM(wParam.ToInt32())] = false;
break;
// Keyboard events:
Please sign in to comment.
Something went wrong with that request. Please try again.