Updated to reflect renames (Windows.API -> Windows.Functions, Keyboard/Mouse -> Keyboard-/MouseDevice)
This commit is contained in:
parent
20f6610c60
commit
d16f2ce71b
3 changed files with 33 additions and 34 deletions
|
@ -58,7 +58,7 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
get
|
||||
{
|
||||
API.GetRawInputDeviceList(null, ref deviceCount, API.RawInputDeviceListSize);
|
||||
Functions.GetRawInputDeviceList(null, ref deviceCount, API.RawInputDeviceListSize);
|
||||
return deviceCount;
|
||||
}
|
||||
}
|
||||
|
@ -78,30 +78,30 @@ namespace OpenTK.Platform.Windows
|
|||
case WindowMessage.INPUT:
|
||||
int size = 0;
|
||||
// Get the size of the input data
|
||||
API.GetRawInputData(msg.LParam, GetRawInputDataEnum.INPUT,
|
||||
Functions.GetRawInputData(msg.LParam, GetRawInputDataEnum.INPUT,
|
||||
IntPtr.Zero, ref size, API.RawInputHeaderSize);
|
||||
|
||||
//if (data == null || API.RawInputSize < size)
|
||||
//{
|
||||
// throw new ApplicationException("Critical error when processing raw windows input.");
|
||||
//}
|
||||
if (size == API.GetRawInputData(msg.LParam, GetRawInputDataEnum.INPUT,
|
||||
if (size == Functions.GetRawInputData(msg.LParam, GetRawInputDataEnum.INPUT,
|
||||
data, ref size, API.RawInputHeaderSize))
|
||||
{
|
||||
switch (data.Header.Type)
|
||||
{
|
||||
case RawInputDeviceType.KEYBOARD:
|
||||
if (!keyboardDriver.ProcessKeyboardEvent(data))
|
||||
API.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
|
||||
Functions.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
|
||||
return;
|
||||
|
||||
case RawInputDeviceType.MOUSE:
|
||||
if (!mouseDriver.ProcessEvent(data))
|
||||
API.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
|
||||
Functions.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
|
||||
return;
|
||||
|
||||
case RawInputDeviceType.HID:
|
||||
API.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
|
||||
Functions.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
|
||||
return;
|
||||
|
||||
default:
|
||||
|
@ -116,7 +116,6 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
break;
|
||||
|
||||
case WindowMessage.CLOSE:
|
||||
case WindowMessage.DESTROY:
|
||||
Debug.Print("Input window detached from parent {0}.", Handle);
|
||||
ReleaseHandle();
|
||||
|
@ -135,12 +134,12 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- IInputDriver Members ---
|
||||
|
||||
public IList<Keyboard> Keyboard
|
||||
public IList<KeyboardDevice> Keyboard
|
||||
{
|
||||
get { return keyboardDriver.Keyboard; }
|
||||
}
|
||||
|
||||
public IList<Mouse> Mouse
|
||||
public IList<MouseDevice> Mouse
|
||||
{
|
||||
get { return mouseDriver.Mouse; }
|
||||
}
|
||||
|
@ -155,7 +154,7 @@ namespace OpenTK.Platform.Windows
|
|||
// structures, calling the correct handler for each one. Last, we free the allocated
|
||||
// buffer.
|
||||
int size = 0;
|
||||
API.GetRawInputBuffer(IntPtr.Zero, ref size, API.RawInputHeaderSize);
|
||||
Functions.GetRawInputBuffer(IntPtr.Zero, ref size, API.RawInputHeaderSize);
|
||||
size *= 256;
|
||||
IntPtr rin_data = Marshal.AllocHGlobal(size);
|
||||
|
||||
|
@ -163,7 +162,7 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
// Iterate reading all available RawInput structures and routing them to their respective
|
||||
// handlers.
|
||||
int num = API.GetRawInputBuffer(rin_data, ref size, API.RawInputHeaderSize);
|
||||
int num = Functions.GetRawInputBuffer(rin_data, ref size, API.RawInputHeaderSize);
|
||||
if (num == 0)
|
||||
break;
|
||||
else if (num < 0)
|
||||
|
@ -200,10 +199,10 @@ namespace OpenTK.Platform.Windows
|
|||
mouseDriver.ProcessEvent(rin_structs[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
next_rin = API.NextRawInputStructure(next_rin);
|
||||
|
||||
next_rin = Functions.NextRawInputStructure(next_rin);
|
||||
}
|
||||
API.DefRawInputProc(rin_structs, num, (uint)API.RawInputHeaderSize);
|
||||
Functions.DefRawInputProc(rin_structs, num, (uint)API.RawInputHeaderSize);
|
||||
}
|
||||
|
||||
Marshal.FreeHGlobal(rin_data);
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
internal class WinRawKeyboard : IKeyboardDriver, IDisposable
|
||||
{
|
||||
private List<Keyboard> keyboards = new List<Keyboard>();
|
||||
private List<KeyboardDevice> keyboards = new List<KeyboardDevice>();
|
||||
private IntPtr window;
|
||||
|
||||
#region internal static Dictionary<VirtualKeys, Input.Key> KeyMap
|
||||
|
@ -163,15 +163,15 @@ namespace OpenTK.Platform.Windows
|
|||
RawInputDeviceList[] ridl = new RawInputDeviceList[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
ridl[i] = new RawInputDeviceList();
|
||||
API.GetRawInputDeviceList(ridl, ref count, API.RawInputDeviceListSize);
|
||||
Functions.GetRawInputDeviceList(ridl, ref count, API.RawInputDeviceListSize);
|
||||
|
||||
// Discover keyboard devices:
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
uint size = 0;
|
||||
API.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, IntPtr.Zero, ref size);
|
||||
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, IntPtr.Zero, ref size);
|
||||
IntPtr name_ptr = Marshal.AllocHGlobal((IntPtr)size);
|
||||
API.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, name_ptr, ref size);
|
||||
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, name_ptr, ref size);
|
||||
string name = Marshal.PtrToStringAnsi(name_ptr);
|
||||
Marshal.FreeHGlobal(name_ptr);
|
||||
if (name.ToLower().Contains("root"))
|
||||
|
@ -206,13 +206,13 @@ namespace OpenTK.Platform.Windows
|
|||
(string)regkey.GetValue("Class");
|
||||
if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("keyboard"))
|
||||
{
|
||||
Keyboard kb = new Keyboard();
|
||||
KeyboardDevice kb = new KeyboardDevice();
|
||||
kb.Description = deviceDesc;
|
||||
|
||||
// Register the keyboard:
|
||||
RawInputDeviceInfo info = new RawInputDeviceInfo();
|
||||
int devInfoSize = API.RawInputDeviceInfoSize;
|
||||
API.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICEINFO,
|
||||
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICEINFO,
|
||||
info, ref devInfoSize);
|
||||
|
||||
kb.NumberOfLeds = info.Device.Keyboard.NumberOfIndicators;
|
||||
|
@ -235,7 +235,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region internal void RegisterKeyboardDevice(Keyboard kb)
|
||||
|
||||
internal void RegisterKeyboardDevice(Keyboard kb)
|
||||
internal void RegisterKeyboardDevice(KeyboardDevice kb)
|
||||
{
|
||||
RawInputDevice[] rid = new RawInputDevice[1];
|
||||
// Keyboard is 1/6 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx
|
||||
|
@ -245,7 +245,7 @@ namespace OpenTK.Platform.Windows
|
|||
rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
|
||||
rid[0].Target = window;
|
||||
|
||||
if (!API.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
|
||||
if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
|
||||
{
|
||||
throw new ApplicationException(
|
||||
String.Format(
|
||||
|
@ -284,7 +284,7 @@ namespace OpenTK.Platform.Windows
|
|||
// came not from a physical keyboard device but from a code-generated input message - in
|
||||
// that case, the event goes to the default (first) keyboard.
|
||||
// TODO: Send the event to all keyboards instead of the default one.
|
||||
int index = keyboards.FindIndex(delegate(Keyboard kb)
|
||||
int index = keyboards.FindIndex(delegate(KeyboardDevice kb)
|
||||
{
|
||||
return kb.DeviceID == rin.Header.Device;
|
||||
});
|
||||
|
@ -342,7 +342,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- IKeyboardDriver Members ---
|
||||
|
||||
public IList<Keyboard> Keyboard
|
||||
public IList<KeyboardDevice> Keyboard
|
||||
{
|
||||
get { return keyboards; }
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// </summary>
|
||||
internal class WinRawMouse : IMouseDriver, IDisposable
|
||||
{
|
||||
private List<Mouse> mice = new List<Mouse>();
|
||||
private List<MouseDevice> mice = new List<MouseDevice>();
|
||||
private IntPtr window;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
@ -45,7 +45,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- IMouseDriver Members ---
|
||||
|
||||
public IList<Mouse> Mouse
|
||||
public IList<MouseDevice> Mouse
|
||||
{
|
||||
get { return mice; }
|
||||
}
|
||||
|
@ -58,15 +58,15 @@ namespace OpenTK.Platform.Windows
|
|||
RawInputDeviceList[] ridl = new RawInputDeviceList[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
ridl[i] = new RawInputDeviceList();
|
||||
API.GetRawInputDeviceList(ridl, ref count, API.RawInputDeviceListSize);
|
||||
Functions.GetRawInputDeviceList(ridl, ref count, API.RawInputDeviceListSize);
|
||||
|
||||
// Discover mouse devices:
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
uint size = 0;
|
||||
API.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, IntPtr.Zero, ref size);
|
||||
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, IntPtr.Zero, ref size);
|
||||
IntPtr name_ptr = Marshal.AllocHGlobal((IntPtr)size);
|
||||
API.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, name_ptr, ref size);
|
||||
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, name_ptr, ref size);
|
||||
string name = Marshal.PtrToStringAnsi(name_ptr);
|
||||
Marshal.FreeHGlobal(name_ptr);
|
||||
|
||||
|
@ -102,13 +102,13 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse"))
|
||||
{
|
||||
OpenTK.Input.Mouse mouse = new OpenTK.Input.Mouse();
|
||||
OpenTK.Input.MouseDevice mouse = new OpenTK.Input.MouseDevice();
|
||||
mouse.Description = deviceDesc;
|
||||
|
||||
// Register the keyboard:
|
||||
RawInputDeviceInfo info = new RawInputDeviceInfo();
|
||||
int devInfoSize = API.RawInputDeviceInfoSize;
|
||||
API.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICEINFO,
|
||||
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICEINFO,
|
||||
info, ref devInfoSize);
|
||||
|
||||
mouse.NumberOfButtons = info.Device.Mouse.NumberOfButtons;
|
||||
|
@ -131,7 +131,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region internal void RegisterRawDevice(OpenTK.Input.Mouse mouse)
|
||||
|
||||
internal void RegisterRawDevice(OpenTK.Input.Mouse mouse)
|
||||
internal void RegisterRawDevice(OpenTK.Input.MouseDevice mouse)
|
||||
{
|
||||
RawInputDevice[] rid = new RawInputDevice[1];
|
||||
// Mouse is 1/2 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx
|
||||
|
@ -141,7 +141,7 @@ namespace OpenTK.Platform.Windows
|
|||
rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
|
||||
rid[0].Target = window;
|
||||
|
||||
if (!API.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
|
||||
if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
|
||||
{
|
||||
throw new ApplicationException(
|
||||
String.Format(
|
||||
|
@ -167,7 +167,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// <returns></returns>
|
||||
internal bool ProcessEvent(RawInput rin)
|
||||
{
|
||||
Mouse mouse = mice.Find(delegate(Mouse m)
|
||||
MouseDevice mouse = mice.Find(delegate(MouseDevice m)
|
||||
{
|
||||
return m.DeviceID == rin.Header.Device;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue