[Win] Cleanup Raw Input HID usage/pages
authorStefanos A <stapostol@gmail.com>
Fri, 17 Jan 2014 12:57:15 +0000 (13:57 +0100)
committerthefiddler <stapostol@gmail.com>
Thu, 11 Sep 2014 10:51:46 +0000 (12:51 +0200)
Source/OpenTK/Platform/Windows/API.cs
Source/OpenTK/Platform/Windows/WinRawKeyboard.cs
Source/OpenTK/Platform/Windows/WinRawMouse.cs

index d8fa295..57a8f29 100644 (file)
@@ -1,12 +1,33 @@
-#region --- License ---
-/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
- * Contributions from Erik Ylvisaker
- * See license.txt for license info
- */
+#region License
+//
+// WinRawJoystick.cs
+//
+// Author:
+//       Stefanos A. <stapostol@gmail.com>
+//
+// Copyright (c) 2006 Stefanos Apostolopoulos
+// Copyright (c) 2007 Erik Ylvisaker
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
 #endregion
 
-#region --- Using Directives ---
-
 using System;
 #if !MINIMAL
 using System.Drawing;
@@ -14,8 +35,7 @@ using System.Drawing;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Security;
-
-#endregion
+using OpenTK.Platform.Common;
 
 /* TODO: Update the description of TimeBeginPeriod and other native methods. Update Timer. */
 
@@ -2424,8 +2444,7 @@ namespace OpenTK.Platform.Windows
         /// <summary>
         /// Top level collection Usage page for the raw input device.
         /// </summary>
-        //internal USHORT UsagePage;
-        internal SHORT UsagePage;
+        internal HIDPage UsagePage;
         /// <summary>
         /// Top level collection Usage for the raw input device.
         /// </summary>
@@ -2443,6 +2462,22 @@ namespace OpenTK.Platform.Windows
         /// </summary>
         internal HWND Target;
 
+        public RawInputDevice(HIDUsageGD usage, RawInputDeviceFlags flags, HWND target)
+        {
+            UsagePage = HIDPage.GenericDesktop;
+            Usage = (short)usage;
+            Flags = flags;
+            Target = target;
+        }
+
+        public RawInputDevice(HIDUsageSim usage, RawInputDeviceFlags flags, HWND target)
+        {
+            UsagePage = HIDPage.Simulation;
+            Usage = (short)usage;
+            Flags = flags;
+            Target = target;
+        }
+
         public override string ToString()
         {
             return String.Format("{0}/{1}, flags: {2}, window: {3}", UsagePage, Usage, Flags, Target);
@@ -2715,16 +2750,15 @@ namespace OpenTK.Platform.Windows
         /// <summary>
         /// Size, in bytes, of each HID input in bRawData.
         /// </summary>
-        internal DWORD SizeHid;
+        internal DWORD Size;
         /// <summary>
         /// Number of HID inputs in bRawData.
         /// </summary>
         internal DWORD Count;
-        // The RawData field must be marshalled manually.
-        ///// <summary>
-        ///// Raw input data as an array of bytes.
-        ///// </summary>
-        //internal IntPtr RawData;
+        /// <summary>
+        /// Raw input data as an array of bytes.
+        /// </summary>
+        internal IntPtr RawData;
     }
 
     #endregion
index ac31979..b5ca8ca 100644 (file)
@@ -33,6 +33,7 @@ using System.Runtime.InteropServices;
 using Microsoft.Win32;
 #endif
 using OpenTK.Input;
+using OpenTK.Platform.Common;
 
 namespace OpenTK.Platform.Windows
 {
@@ -241,13 +242,10 @@ namespace OpenTK.Platform.Windows
 
         static void RegisterKeyboardDevice(IntPtr window, string name)
         {
-            RawInputDevice[] rid = new RawInputDevice[1];
-            // Keyboard is 1/6 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx
-            rid[0] = new RawInputDevice();
-            rid[0].UsagePage = 1;
-            rid[0].Usage = 6;
-            rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
-            rid[0].Target = window;
+            RawInputDevice[] rid = new RawInputDevice[]
+            {
+                new RawInputDevice(HIDUsageGD.Keyboard, RawInputDeviceFlags.INPUTSINK, window)
+            };
 
             if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
             {
index 3add448..11d7042 100644 (file)
@@ -31,6 +31,7 @@ using System.Diagnostics;
 using System.Runtime.InteropServices;
 using Microsoft.Win32;
 using OpenTK.Input;
+using OpenTK.Platform.Common;
 
 namespace OpenTK.Platform.Windows
 {
@@ -296,13 +297,10 @@ namespace OpenTK.Platform.Windows
 
         static void RegisterRawDevice(IntPtr window, string device)
         {
-            RawInputDevice[] rid = new RawInputDevice[1];
-            // Mouse is 1/2 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx
-            rid[0] = new RawInputDevice();
-            rid[0].UsagePage = 1;
-            rid[0].Usage = 2;
-            rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
-            rid[0].Target = window;
+            RawInputDevice[] rid = new RawInputDevice[]
+            {
+                new RawInputDevice(HIDUsageGD.Mouse, RawInputDeviceFlags.INPUTSINK, window)
+            };
 
             if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
             {