[Win] Added helper raw input methods

This commit is contained in:
thefiddler 2014-07-31 15:43:13 +02:00
parent 6d54edc389
commit a51a85c517

View file

@ -94,6 +94,7 @@ namespace OpenTK.Platform.Windows
using TIMERPROC = Functions.TimerProc; using TIMERPROC = Functions.TimerProc;
using REGSAM = System.UInt32; using REGSAM = System.UInt32;
using System.Diagnostics;
#endregion #endregion
@ -1646,6 +1647,52 @@ namespace OpenTK.Platform.Windows
INT SizeHeader 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 #endregion
#region IntPtr NextRawInputStructure(IntPtr data) #region IntPtr NextRawInputStructure(IntPtr data)
@ -2529,6 +2576,9 @@ namespace OpenTK.Platform.Windows
{ {
public RawInputHeader Header; public RawInputHeader Header;
public RawInputData Data; public RawInputData Data;
public static readonly int SizeInBytes =
BlittableValueType<RawInput>.Stride;
} }
[StructLayout(LayoutKind.Explicit)] [StructLayout(LayoutKind.Explicit)]
@ -2540,6 +2590,9 @@ namespace OpenTK.Platform.Windows
internal RawKeyboard Keyboard; internal RawKeyboard Keyboard;
[FieldOffset(0)] [FieldOffset(0)]
internal RawHID HID; internal RawHID HID;
public static readonly int SizeInBytes =
BlittableValueType<RawInputData>.Stride;
} }
#endregion #endregion
@ -2572,6 +2625,9 @@ namespace OpenTK.Platform.Windows
/// Value passed in the wParam parameter of the WM_INPUT message. /// Value passed in the wParam parameter of the WM_INPUT message.
/// </summary> /// </summary>
internal WPARAM Param; internal WPARAM Param;
public static readonly int SizeInBytes =
BlittableValueType<RawInputHeader>.Stride;
} }
#endregion #endregion