Fixed Raw Input keyboard registration under windows.

Fixed marshalling in GetRawInputData.
This commit is contained in:
the_fiddler 2007-07-27 01:37:12 +00:00
parent 20630278fb
commit 8c43b52517
5 changed files with 57 additions and 17 deletions

View file

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
#region --- License ---
/* Copyright (c) 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
namespace OpenTK.Input
{

View file

@ -1,6 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
#region --- License ---
/* Copyright (c) 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
#region --- Using directives ---
using System;
#endregion
namespace OpenTK.Input
{

View file

@ -56,6 +56,7 @@ namespace OpenTK.Platform.Windows
{
RawInputHeaderSize = (uint)Marshal.SizeOf(typeof(RawInputHeader));
RawInputSize = (uint)Marshal.SizeOf(typeof(RawInput));
RawInputDeviceSize = (uint)Marshal.SizeOf(typeof(RawInputDevice));
}
#region Constants
@ -905,7 +906,7 @@ namespace OpenTK.Platform.Windows
public static extern UINT GetRawInputData(
HRAWINPUT RawInput,
GetRawInputDataEnum Command,
[MarshalAs(UnmanagedType.Struct)] [Out] RawInput Data,
[MarshalAs(UnmanagedType.LPStruct)] [Out] RawInput Data,
[In, Out] ref UINT Size,
UINT SizeHeader
);
@ -1316,6 +1317,8 @@ namespace OpenTK.Platform.Windows
#region RawInputDevice
public static readonly uint RawInputDeviceSize;
/// <summary>
/// Defines information for the raw input devices.
/// </summary>
@ -1323,7 +1326,7 @@ namespace OpenTK.Platform.Windows
/// If RIDEV_NOLEGACY is set for a mouse or a keyboard, the system does not generate any legacy message for that device for the application. For example, if the mouse TLC is set with RIDEV_NOLEGACY, WM_LBUTTONDOWN and related legacy mouse messages are not generated. Likewise, if the keyboard TLC is set with RIDEV_NOLEGACY, WM_KEYDOWN and related legacy keyboard messages are not generated.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public class RawInputDevice
public struct RawInputDevice
{
/// <summary>
/// Top level collection Usage page for the raw input device.
@ -1344,6 +1347,11 @@ namespace OpenTK.Platform.Windows
/// Handle to the target window. If NULL it follows the keyboard focus.
/// </summary>
public HWND Target;
public override string ToString()
{
return String.Format("{0}/{1}, flags: {2}, window: {3}", UsagePage, Usage, Flags, Target);
}
}
#endregion
@ -1769,6 +1777,7 @@ namespace OpenTK.Platform.Windows
#region RawInputDeviceFlags enum
[Flags]
public enum RawInputDeviceFlags : int
{
/// <summary>

View file

@ -1,9 +1,19 @@
using System;
#region --- License ---
/* Copyright (c) 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
#region --- Using directives ---
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
#endregion
namespace OpenTK.Platform.Windows
{
static class WinRawInput

View file

@ -1,10 +1,20 @@
using System;
#region --- License ---
/* Copyright (c) 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
#region --- Using directives ---
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using OpenTK.Input;
#endregion
namespace OpenTK.Platform.Windows
{
internal class WinRawKeyboard : OpenTK.Input.IKeyboard
@ -24,17 +34,18 @@ namespace OpenTK.Platform.Windows
rid[0].UsagePage = 1;
rid[0].Usage = 6;
rid[0].Flags =
API.RawInputDeviceFlags.APPKEYS |
API.RawInputDeviceFlags.NOLEGACY;
rid[0].Flags = API.RawInputDeviceFlags.INPUTSINK;
rid[0].Target = windowHandle;
if (!API.RegisterRawInputDevices(rid, 1, API.RawInputHeaderSize))
if (!API.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
{
/*throw new ApplicationException(
String.Format("Raw input registration failed for keyboard. Error {0}", Marshal.GetLastWin32Error())
);*/
throw new ApplicationException(
String.Format(
"Raw input registration failed with error: {0}. Device: {1}",
Marshal.GetLastWin32Error(),
rid[0].ToString())
);
}
}