From 2c197f09e1fb19754f15d9ea00c1e83c3eaea387 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Fri, 17 Jan 2014 13:57:15 +0100 Subject: [PATCH] [Win] Cleanup Raw Input HID usage/pages --- Source/OpenTK/Platform/Windows/API.cs | 68 ++++++++++++++++++------ Source/OpenTK/Platform/Windows/WinRawKeyboard.cs | 12 ++--- Source/OpenTK/Platform/Windows/WinRawMouse.cs | 12 ++--- 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index d8fa295..57a8f29 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -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. +// +// 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 /// /// Top level collection Usage page for the raw input device. /// - //internal USHORT UsagePage; - internal SHORT UsagePage; + internal HIDPage UsagePage; /// /// Top level collection Usage for the raw input device. /// @@ -2443,6 +2462,22 @@ namespace OpenTK.Platform.Windows /// 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 /// /// Size, in bytes, of each HID input in bRawData. /// - internal DWORD SizeHid; + internal DWORD Size; /// /// Number of HID inputs in bRawData. /// internal DWORD Count; - // The RawData field must be marshalled manually. - ///// - ///// Raw input data as an array of bytes. - ///// - //internal IntPtr RawData; + /// + /// Raw input data as an array of bytes. + /// + internal IntPtr RawData; } #endregion diff --git a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs index ac31979..b5ca8ca 100644 --- a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs +++ b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs @@ -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)) { diff --git a/Source/OpenTK/Platform/Windows/WinRawMouse.cs b/Source/OpenTK/Platform/Windows/WinRawMouse.cs index 3add448..11d7042 100644 --- a/Source/OpenTK/Platform/Windows/WinRawMouse.cs +++ b/Source/OpenTK/Platform/Windows/WinRawMouse.cs @@ -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)) { -- 2.7.4