2007-07-27 01:37:12 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Using directives ---
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-07-27 01:20:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2007-08-03 00:14:31 +00:00
|
|
|
|
using System.Diagnostics;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using OpenTK.Input;
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-07-27 01:37:12 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-27 01:20:55 +00:00
|
|
|
|
namespace OpenTK.Platform.Windows
|
|
|
|
|
{
|
2007-08-22 00:30:16 +00:00
|
|
|
|
internal class WinRawKeyboard : IKeyboardDriver, IDisposable
|
2007-07-27 01:20:55 +00:00
|
|
|
|
{
|
2007-09-26 11:57:32 +00:00
|
|
|
|
private List<KeyboardDevice> keyboards = new List<KeyboardDevice>();
|
2007-09-21 20:03:53 +00:00
|
|
|
|
private IntPtr window;
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
2007-09-02 00:16:22 +00:00
|
|
|
|
#region internal static Dictionary<VirtualKeys, Input.Key> KeyMap
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
2007-09-02 00:16:22 +00:00
|
|
|
|
internal static Dictionary<VirtualKeys, Input.Key> KeyMap =
|
|
|
|
|
new Dictionary<VirtualKeys, Input.Key>((int)VirtualKeys.Last);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
private static bool keyMapExists;
|
|
|
|
|
/// <summary>
|
2007-08-05 16:04:39 +00:00
|
|
|
|
/// Initializes the map between VirtualKeys and OpenTK.Key
|
2007-08-03 00:14:31 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
private static void InitKeyMap()
|
|
|
|
|
{
|
|
|
|
|
if (!keyMapExists)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add(VirtualKeys.ESCAPE, Key.Escape);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
// Function keys
|
|
|
|
|
for (int i = 0; i < 24; i++)
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add((VirtualKeys)((int)VirtualKeys.F1 + i), Key.F1 + i);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Number keys (0-9)
|
|
|
|
|
for (int i = 0; i <= 9; i++)
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add((VirtualKeys)(0x30 + i), Key.Number0 + i);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Letters (A-Z)
|
|
|
|
|
for (int i = 0; i < 26; i++)
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add((VirtualKeys)(0x41 + i), Key.A + i);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add(VirtualKeys.TAB, Key.Tab);
|
|
|
|
|
KeyMap.Add(VirtualKeys.CAPITAL, Key.CapsLock);
|
|
|
|
|
KeyMap.Add(VirtualKeys.LCONTROL, Key.ControlLeft);
|
|
|
|
|
KeyMap.Add(VirtualKeys.LSHIFT, Key.ShiftLeft);
|
|
|
|
|
KeyMap.Add(VirtualKeys.LWIN, Key.WinLeft);
|
|
|
|
|
KeyMap.Add(VirtualKeys.LMENU, Key.AltLeft);
|
|
|
|
|
KeyMap.Add(VirtualKeys.SPACE, Key.Space);
|
|
|
|
|
KeyMap.Add(VirtualKeys.RMENU, Key.AltRight);
|
|
|
|
|
KeyMap.Add(VirtualKeys.RWIN, Key.WinRight);
|
|
|
|
|
KeyMap.Add(VirtualKeys.APPS, Key.Menu);
|
|
|
|
|
KeyMap.Add(VirtualKeys.RCONTROL, Key.ControlRight);
|
|
|
|
|
KeyMap.Add(VirtualKeys.RSHIFT, Key.ShiftRight);
|
|
|
|
|
KeyMap.Add(VirtualKeys.RETURN, Key.Enter);
|
|
|
|
|
KeyMap.Add(VirtualKeys.BACK, Key.BackSpace);
|
|
|
|
|
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_1, Key.Semicolon); // Varies by keyboard, ;: on Win2K/US
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_2, Key.Slash); // Varies by keyboard, /? on Win2K/US
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_3, Key.Tilde); // Varies by keyboard, `~ on Win2K/US
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_4, Key.BracketLeft); // Varies by keyboard, [{ on Win2K/US
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_5, Key.BackSlash); // Varies by keyboard, \| on Win2K/US
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_6, Key.BracketRight); // Varies by keyboard, ]} on Win2K/US
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_7, Key.Quote); // Varies by keyboard, '" on Win2K/US
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_PLUS, Key.Plus); // Invariant: +
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_COMMA, Key.Comma); // Invariant: ,
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_MINUS, Key.Minus); // Invariant: -
|
|
|
|
|
KeyMap.Add(VirtualKeys.OEM_PERIOD, Key.Period); // Invariant: .
|
|
|
|
|
|
|
|
|
|
KeyMap.Add(VirtualKeys.HOME, Key.Home);
|
|
|
|
|
KeyMap.Add(VirtualKeys.END, Key.End);
|
|
|
|
|
KeyMap.Add(VirtualKeys.DELETE, Key.Delete);
|
|
|
|
|
KeyMap.Add(VirtualKeys.PRIOR, Key.PageUp);
|
|
|
|
|
KeyMap.Add(VirtualKeys.NEXT, Key.PageDown);
|
|
|
|
|
KeyMap.Add(VirtualKeys.PRINT, Key.PrintScreen);
|
|
|
|
|
KeyMap.Add(VirtualKeys.PAUSE, Key.Pause);
|
|
|
|
|
KeyMap.Add(VirtualKeys.NUMLOCK, Key.NumLock);
|
|
|
|
|
|
|
|
|
|
KeyMap.Add(VirtualKeys.SCROLL, Key.ScrollLock);
|
|
|
|
|
KeyMap.Add(VirtualKeys.SNAPSHOT, Key.PrintScreen);
|
|
|
|
|
KeyMap.Add(VirtualKeys.CLEAR, Key.Clear);
|
|
|
|
|
KeyMap.Add(VirtualKeys.INSERT, Key.Insert);
|
|
|
|
|
|
|
|
|
|
KeyMap.Add(VirtualKeys.SLEEP, Key.Sleep);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
// Keypad
|
|
|
|
|
for (int i = 0; i <= 9; i++)
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add((VirtualKeys)((int)VirtualKeys.NUMPAD0 + i), Key.Keypad0 + i);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add(VirtualKeys.DECIMAL, Key.KeypadDecimal);
|
|
|
|
|
KeyMap.Add(VirtualKeys.ADD, Key.KeypadAdd);
|
|
|
|
|
KeyMap.Add(VirtualKeys.SUBTRACT, Key.KeypadSubtract);
|
|
|
|
|
KeyMap.Add(VirtualKeys.DIVIDE, Key.KeypadDivide);
|
|
|
|
|
KeyMap.Add(VirtualKeys.MULTIPLY, Key.KeypadMultiply);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
// Navigation
|
2007-09-21 20:03:53 +00:00
|
|
|
|
KeyMap.Add(VirtualKeys.UP, Key.Up);
|
|
|
|
|
KeyMap.Add(VirtualKeys.DOWN, Key.Down);
|
|
|
|
|
KeyMap.Add(VirtualKeys.LEFT, Key.Left);
|
|
|
|
|
KeyMap.Add(VirtualKeys.RIGHT, Key.Right);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException e)
|
|
|
|
|
{
|
|
|
|
|
Debug.Print("Exception while creating keymap: '{0}'.", e.ToString());
|
|
|
|
|
System.Windows.Forms.MessageBox.Show(
|
|
|
|
|
String.Format("Exception while creating keymap: '{0}'.", e.ToString()));
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
keyMapExists = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
|
|
|
|
internal WinRawKeyboard()
|
|
|
|
|
: this(IntPtr.Zero)
|
2007-08-03 00:14:31 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
internal WinRawKeyboard(IntPtr windowHandle)
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
Debug.WriteLine("Initializing keyboard driver (WinRawKeyboard).");
|
2007-08-04 12:09:58 +00:00
|
|
|
|
Debug.Indent();
|
|
|
|
|
|
2007-09-21 20:03:53 +00:00
|
|
|
|
this.window = windowHandle;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
InitKeyMap();
|
|
|
|
|
|
|
|
|
|
UpdateKeyboardList();
|
|
|
|
|
|
|
|
|
|
Debug.Unindent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region internal static void UpdateKeyboardList()
|
|
|
|
|
|
|
|
|
|
internal void UpdateKeyboardList()
|
2007-08-03 00:14:31 +00:00
|
|
|
|
{
|
2007-08-05 00:09:42 +00:00
|
|
|
|
int count = WinRawInput.DeviceCount;
|
2007-09-02 00:16:22 +00:00
|
|
|
|
RawInputDeviceList[] ridl = new RawInputDeviceList[count];
|
2007-08-03 00:14:31 +00:00
|
|
|
|
for (int i = 0; i < count; i++)
|
2007-09-02 00:16:22 +00:00
|
|
|
|
ridl[i] = new RawInputDeviceList();
|
2007-09-26 11:57:32 +00:00
|
|
|
|
Functions.GetRawInputDeviceList(ridl, ref count, API.RawInputDeviceListSize);
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
// Discover keyboard devices:
|
2007-08-03 00:14:31 +00:00
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
uint size = 0;
|
2007-09-26 11:57:32 +00:00
|
|
|
|
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, IntPtr.Zero, ref size);
|
2007-08-04 12:09:58 +00:00
|
|
|
|
IntPtr name_ptr = Marshal.AllocHGlobal((IntPtr)size);
|
2007-09-26 11:57:32 +00:00
|
|
|
|
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, name_ptr, ref size);
|
2007-08-04 12:09:58 +00:00
|
|
|
|
string name = Marshal.PtrToStringAnsi(name_ptr);
|
|
|
|
|
Marshal.FreeHGlobal(name_ptr);
|
|
|
|
|
if (name.ToLower().Contains("root"))
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
// This is a terminal services device, skip it.
|
2007-08-04 12:09:58 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-09-02 00:16:22 +00:00
|
|
|
|
else if (ridl[i].Type == RawInputDeviceType.KEYBOARD || ridl[i].Type == RawInputDeviceType.HID)
|
2007-08-04 12:09:58 +00:00
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
// This is a keyboard or USB keyboard device. In the latter case, discover if it really is a
|
|
|
|
|
// keyboard device by qeurying the registry.
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
|
|
|
|
// remove the \??\
|
|
|
|
|
name = name.Substring(4);
|
|
|
|
|
|
|
|
|
|
string[] split = name.Split('#');
|
|
|
|
|
|
|
|
|
|
string id_01 = split[0]; // ACPI (Class code)
|
|
|
|
|
string id_02 = split[1]; // PNP0303 (SubClass code)
|
|
|
|
|
string id_03 = split[2]; // 3&13c0b0c5&0 (Protocol code)
|
|
|
|
|
// The final part is the class GUID and is not needed here
|
|
|
|
|
|
|
|
|
|
string findme = string.Format(
|
|
|
|
|
@"System\CurrentControlSet\Enum\{0}\{1}\{2}",
|
|
|
|
|
id_01, id_02, id_03);
|
|
|
|
|
|
|
|
|
|
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(findme);
|
|
|
|
|
|
|
|
|
|
string deviceDesc =
|
|
|
|
|
(string)regkey.GetValue("DeviceDesc");
|
|
|
|
|
string deviceClass =
|
|
|
|
|
(string)regkey.GetValue("Class");
|
|
|
|
|
if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("keyboard"))
|
|
|
|
|
{
|
2007-09-26 11:57:32 +00:00
|
|
|
|
KeyboardDevice kb = new KeyboardDevice();
|
2007-08-04 12:09:58 +00:00
|
|
|
|
kb.Description = deviceDesc;
|
|
|
|
|
|
|
|
|
|
// Register the keyboard:
|
2007-09-02 00:16:22 +00:00
|
|
|
|
RawInputDeviceInfo info = new RawInputDeviceInfo();
|
2007-08-05 00:09:42 +00:00
|
|
|
|
int devInfoSize = API.RawInputDeviceInfoSize;
|
2007-09-26 11:57:32 +00:00
|
|
|
|
Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICEINFO,
|
2007-08-04 12:09:58 +00:00
|
|
|
|
info, ref devInfoSize);
|
|
|
|
|
|
|
|
|
|
kb.NumberOfLeds = info.Device.Keyboard.NumberOfIndicators;
|
|
|
|
|
kb.NumberOfFunctionKeys = info.Device.Keyboard.NumberOfFunctionKeys;
|
|
|
|
|
kb.NumberOfKeys = info.Device.Keyboard.NumberOfKeysTotal;
|
2007-09-21 20:03:53 +00:00
|
|
|
|
//kb.DeviceID = (info.Device.Keyboard.Type << 32) + info.Device.Keyboard.SubType;
|
|
|
|
|
kb.DeviceID = ridl[i].Device;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
2007-09-21 20:03:53 +00:00
|
|
|
|
//if (!keyboards.Contains(kb))
|
|
|
|
|
//{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
this.RegisterKeyboardDevice(kb);
|
|
|
|
|
keyboards.Add(kb);
|
2007-09-21 20:03:53 +00:00
|
|
|
|
//}
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#endregion
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#region internal void RegisterKeyboardDevice(Keyboard kb)
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-09-26 11:57:32 +00:00
|
|
|
|
internal void RegisterKeyboardDevice(KeyboardDevice kb)
|
2007-07-27 01:20:55 +00:00
|
|
|
|
{
|
2007-09-02 00:16:22 +00:00
|
|
|
|
RawInputDevice[] rid = new RawInputDevice[1];
|
2007-07-27 01:20:55 +00:00
|
|
|
|
// Keyboard is 1/6 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx
|
2007-09-02 00:16:22 +00:00
|
|
|
|
rid[0] = new RawInputDevice();
|
2007-07-27 01:20:55 +00:00
|
|
|
|
rid[0].UsagePage = 1;
|
|
|
|
|
rid[0].Usage = 6;
|
2007-09-02 00:16:22 +00:00
|
|
|
|
rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
|
2007-09-21 20:03:53 +00:00
|
|
|
|
rid[0].Target = window;
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-09-26 11:57:32 +00:00
|
|
|
|
if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
|
2007-07-27 01:20:55 +00:00
|
|
|
|
{
|
2007-07-27 01:37:12 +00:00
|
|
|
|
throw new ApplicationException(
|
|
|
|
|
String.Format(
|
|
|
|
|
"Raw input registration failed with error: {0}. Device: {1}",
|
|
|
|
|
Marshal.GetLastWin32Error(),
|
|
|
|
|
rid[0].ToString())
|
|
|
|
|
);
|
2007-07-27 01:20:55 +00:00
|
|
|
|
}
|
2007-08-04 12:09:58 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Print("Registered keyboard {0}", kb.ToString());
|
|
|
|
|
}
|
2007-07-27 01:20:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-31 21:50:29 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#region internal bool ProcessKeyboardEvent(API.RawInput rin)
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Processes raw input events.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rin"></param>
|
|
|
|
|
/// <returns></returns>
|
2007-09-02 00:16:22 +00:00
|
|
|
|
internal bool ProcessKeyboardEvent(RawInput rin)
|
2007-07-27 01:20:55 +00:00
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
//Keyboard key = keyboards[0];
|
|
|
|
|
//rin.Header.Device;
|
|
|
|
|
switch (rin.Header.Type)
|
2007-07-27 01:20:55 +00:00
|
|
|
|
{
|
2007-09-02 00:16:22 +00:00
|
|
|
|
case RawInputDeviceType.KEYBOARD:
|
2007-08-04 12:09:58 +00:00
|
|
|
|
bool pressed =
|
2007-09-02 00:16:22 +00:00
|
|
|
|
rin.Data.Keyboard.Message == (int)WindowMessage.KEYDOWN ||
|
|
|
|
|
rin.Data.Keyboard.Message == (int)WindowMessage.SYSKEYDOWN;
|
2007-09-21 22:49:42 +00:00
|
|
|
|
|
|
|
|
|
// Find the device where the button was pressed. It can be that the input notification
|
|
|
|
|
// 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.
|
2007-09-26 11:57:32 +00:00
|
|
|
|
int index = keyboards.FindIndex(delegate(KeyboardDevice kb)
|
2007-09-21 20:03:53 +00:00
|
|
|
|
{
|
|
|
|
|
return kb.DeviceID == rin.Header.Device;
|
|
|
|
|
});
|
2007-09-21 22:49:42 +00:00
|
|
|
|
if (index == -1) index = 0;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
|
|
|
|
// Generic control, shift, alt keys may be sent instead of left/right.
|
|
|
|
|
// It seems you have to explicitly register left/right events.
|
|
|
|
|
switch (rin.Data.Keyboard.VKey)
|
|
|
|
|
{
|
2007-09-02 00:16:22 +00:00
|
|
|
|
case VirtualKeys.SHIFT:
|
2007-09-21 20:03:53 +00:00
|
|
|
|
keyboards[index][Input.Key.ShiftLeft] = keyboards[index][Input.Key.ShiftRight] = pressed;
|
2007-08-22 00:30:16 +00:00
|
|
|
|
return true;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
2007-09-02 00:16:22 +00:00
|
|
|
|
case VirtualKeys.CONTROL:
|
2007-09-21 20:03:53 +00:00
|
|
|
|
keyboards[index][Input.Key.ControlLeft] = keyboards[index][Input.Key.ControlRight] = pressed;
|
2007-08-22 00:30:16 +00:00
|
|
|
|
return true;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
2007-09-02 00:16:22 +00:00
|
|
|
|
case VirtualKeys.MENU:
|
2007-09-21 20:03:53 +00:00
|
|
|
|
keyboards[index][Input.Key.AltLeft] = keyboards[index][Input.Key.AltRight] = pressed;
|
2007-08-22 00:30:16 +00:00
|
|
|
|
return true;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (!WinRawKeyboard.KeyMap.ContainsKey(rin.Data.Keyboard.VKey))
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
Debug.Print("Virtual key {0} ({1}) not mapped.",
|
|
|
|
|
rin.Data.Keyboard.VKey, (int)rin.Data.Keyboard.VKey);
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-09-21 20:03:53 +00:00
|
|
|
|
keyboards[index][WinRawKeyboard.KeyMap[rin.Data.Keyboard.VKey]] = pressed;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
2007-08-22 00:30:16 +00:00
|
|
|
|
return false;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new ApplicationException("Windows raw keyboard driver received invalid data.");
|
2007-07-27 01:20:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
#region --- IInputDevice Members ---
|
|
|
|
|
|
|
|
|
|
public string Description
|
|
|
|
|
{
|
|
|
|
|
get { throw new Exception("The method or operation is not implemented."); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Input.InputDeviceType DeviceType
|
|
|
|
|
{
|
|
|
|
|
get { return Input.InputDeviceType.Keyboard; }
|
|
|
|
|
}
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
#endregion
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
|
|
|
|
#region --- IKeyboardDriver Members ---
|
|
|
|
|
|
2007-09-26 11:57:32 +00:00
|
|
|
|
public IList<KeyboardDevice> Keyboard
|
2007-08-04 12:09:58 +00:00
|
|
|
|
{
|
|
|
|
|
get { return keyboards; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-22 00:30:16 +00:00
|
|
|
|
|
|
|
|
|
#region --- IDisposable Members ---
|
|
|
|
|
|
|
|
|
|
private bool disposed;
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dispose(bool manual)
|
|
|
|
|
{
|
|
|
|
|
if (!disposed)
|
|
|
|
|
{
|
|
|
|
|
if (manual)
|
|
|
|
|
{
|
2007-09-02 00:16:22 +00:00
|
|
|
|
keyboards.Clear();
|
2007-08-22 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~WinRawKeyboard()
|
|
|
|
|
{
|
|
|
|
|
Dispose(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
2007-07-27 01:20:55 +00:00
|
|
|
|
}
|