[Win] Cleanup Raw Input HID usage/pages

This commit is contained in:
Stefanos A 2014-01-17 13:57:15 +01:00 committed by thefiddler
parent cac96bbaf9
commit 2c197f09e1
3 changed files with 61 additions and 31 deletions

View file

@ -1,12 +1,33 @@
#region --- License --- #region License
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos //
* Contributions from Erik Ylvisaker // WinRawJoystick.cs
* See license.txt for license info //
*/ // 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 #endregion
#region --- Using Directives ---
using System; using System;
#if !MINIMAL #if !MINIMAL
using System.Drawing; using System.Drawing;
@ -14,8 +35,7 @@ using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Security; using System.Security;
using OpenTK.Platform.Common;
#endregion
/* TODO: Update the description of TimeBeginPeriod and other native methods. Update Timer. */ /* TODO: Update the description of TimeBeginPeriod and other native methods. Update Timer. */
@ -2424,8 +2444,7 @@ namespace OpenTK.Platform.Windows
/// <summary> /// <summary>
/// Top level collection Usage page for the raw input device. /// Top level collection Usage page for the raw input device.
/// </summary> /// </summary>
//internal USHORT UsagePage; internal HIDPage UsagePage;
internal SHORT UsagePage;
/// <summary> /// <summary>
/// Top level collection Usage for the raw input device. /// Top level collection Usage for the raw input device.
/// </summary> /// </summary>
@ -2443,6 +2462,22 @@ namespace OpenTK.Platform.Windows
/// </summary> /// </summary>
internal HWND Target; 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() public override string ToString()
{ {
return String.Format("{0}/{1}, flags: {2}, window: {3}", UsagePage, Usage, Flags, Target); return String.Format("{0}/{1}, flags: {2}, window: {3}", UsagePage, Usage, Flags, Target);
@ -2715,16 +2750,15 @@ namespace OpenTK.Platform.Windows
/// <summary> /// <summary>
/// Size, in bytes, of each HID input in bRawData. /// Size, in bytes, of each HID input in bRawData.
/// </summary> /// </summary>
internal DWORD SizeHid; internal DWORD Size;
/// <summary> /// <summary>
/// Number of HID inputs in bRawData. /// Number of HID inputs in bRawData.
/// </summary> /// </summary>
internal DWORD Count; internal DWORD Count;
// The RawData field must be marshalled manually. /// <summary>
///// <summary> /// Raw input data as an array of bytes.
///// Raw input data as an array of bytes. /// </summary>
///// </summary> internal IntPtr RawData;
//internal IntPtr RawData;
} }
#endregion #endregion

View file

@ -33,6 +33,7 @@ using System.Runtime.InteropServices;
using Microsoft.Win32; using Microsoft.Win32;
#endif #endif
using OpenTK.Input; using OpenTK.Input;
using OpenTK.Platform.Common;
namespace OpenTK.Platform.Windows namespace OpenTK.Platform.Windows
{ {
@ -241,13 +242,10 @@ namespace OpenTK.Platform.Windows
static void RegisterKeyboardDevice(IntPtr window, string name) static void RegisterKeyboardDevice(IntPtr window, string name)
{ {
RawInputDevice[] rid = new RawInputDevice[1]; RawInputDevice[] rid = new RawInputDevice[]
// Keyboard is 1/6 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx {
rid[0] = new RawInputDevice(); new RawInputDevice(HIDUsageGD.Keyboard, RawInputDeviceFlags.INPUTSINK, window)
rid[0].UsagePage = 1; };
rid[0].Usage = 6;
rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
rid[0].Target = window;
if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize)) if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
{ {

View file

@ -31,6 +31,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Win32; using Microsoft.Win32;
using OpenTK.Input; using OpenTK.Input;
using OpenTK.Platform.Common;
namespace OpenTK.Platform.Windows namespace OpenTK.Platform.Windows
{ {
@ -296,13 +297,10 @@ namespace OpenTK.Platform.Windows
static void RegisterRawDevice(IntPtr window, string device) static void RegisterRawDevice(IntPtr window, string device)
{ {
RawInputDevice[] rid = new RawInputDevice[1]; RawInputDevice[] rid = new RawInputDevice[]
// Mouse is 1/2 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx {
rid[0] = new RawInputDevice(); new RawInputDevice(HIDUsageGD.Mouse, RawInputDeviceFlags.INPUTSINK, window)
rid[0].UsagePage = 1; };
rid[0].Usage = 2;
rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
rid[0].Target = window;
if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize)) if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
{ {