From a51a85c51736c1c69291dc70e1eac3a1fc46c8f8 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Thu, 31 Jul 2014 15:43:13 +0200 Subject: [PATCH] [Win] Added helper raw input methods --- Source/OpenTK/Platform/Windows/API.cs | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index fe17602..05d5e73 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -94,6 +94,7 @@ namespace OpenTK.Platform.Windows using TIMERPROC = Functions.TimerProc; using REGSAM = System.UInt32; + using System.Diagnostics; #endregion @@ -1646,6 +1647,52 @@ namespace OpenTK.Platform.Windows INT SizeHeader ); + internal static int GetRawInputData(IntPtr raw, out RawInputHeader header) + { + int size = RawInputHeader.SizeInBytes; + unsafe + { + fixed (RawInputHeader* pheader = &header) + { + if (GetRawInputData(raw, GetRawInputDataEnum.HEADER, + (IntPtr)pheader, ref size, API.RawInputHeaderSize) != RawInputHeader.SizeInBytes) + { + Debug.Print("[Error] Failed to retrieve raw input header. Error: {0}", + Marshal.GetLastWin32Error()); + } + } + } + return size; + } + + internal static int GetRawInputData(IntPtr raw, out RawInput data) + { + int size = RawInput.SizeInBytes; + unsafe + { + fixed (RawInput* pdata = &data) + { + GetRawInputData(raw, GetRawInputDataEnum.INPUT, + (IntPtr)pdata, ref size, API.RawInputHeaderSize); + } + } + return size; + } + + internal static int GetRawInputData(IntPtr raw, byte[] data) + { + int size = data.Length; + unsafe + { + fixed (byte* pdata = data) + { + GetRawInputData(raw, GetRawInputDataEnum.INPUT, + (IntPtr)pdata, ref size, API.RawInputHeaderSize); + } + } + return size; + } + #endregion #region IntPtr NextRawInputStructure(IntPtr data) @@ -2529,6 +2576,9 @@ namespace OpenTK.Platform.Windows { public RawInputHeader Header; public RawInputData Data; + + public static readonly int SizeInBytes = + BlittableValueType.Stride; } [StructLayout(LayoutKind.Explicit)] @@ -2540,6 +2590,9 @@ namespace OpenTK.Platform.Windows internal RawKeyboard Keyboard; [FieldOffset(0)] internal RawHID HID; + + public static readonly int SizeInBytes = + BlittableValueType.Stride; } #endregion @@ -2572,6 +2625,9 @@ namespace OpenTK.Platform.Windows /// Value passed in the wParam parameter of the WM_INPUT message. /// internal WPARAM Param; + + public static readonly int SizeInBytes = + BlittableValueType.Stride; } #endregion -- 2.7.4