# HG changeset patch
# User sl
# Date 1417830406 -3600
# Node ID 8b2a3da541873e688b3be93430a0c5729e85babb
# Parent fb4f80d5cf579ffa5c419662de544e5942868690
Adding method to get the device name.
diff -r fb4f80d5cf57 -r 8b2a3da54187 RawInput.cs
--- a/RawInput.cs Sat Dec 06 01:53:55 2014 +0100
+++ b/RawInput.cs Sat Dec 06 02:46:46 2014 +0100
@@ -68,7 +68,7 @@
uint deviceInfoSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO));
deviceInfoBuffer = Marshal.AllocHGlobal((int)deviceInfoSize);
- int res = Win32.Function.GetRawInputDeviceInfo(hDevice, Const.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize);
+ int res = Win32.Function.GetRawInputDeviceInfoW(hDevice, Const.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize);
if (res <= 0)
{
Debug.WriteLine("WM_INPUT could not read device info: " + Marshal.GetLastWin32Error().ToString());
@@ -101,7 +101,7 @@
public static IntPtr GetPreParsedData(IntPtr hDevice)
{
uint ppDataSize = 256;
- int result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize);
+ int result = Win32.Function.GetRawInputDeviceInfoW(hDevice, Win32.Const.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize);
if (result != 0)
{
Debug.WriteLine("Failed to get raw input pre-parsed data size" + result + Marshal.GetLastWin32Error());
@@ -109,7 +109,7 @@
}
IntPtr ppData = Marshal.AllocHGlobal((int)ppDataSize);
- result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, ppData, ref ppDataSize);
+ result = Win32.Function.GetRawInputDeviceInfoW(hDevice, Win32.Const.RIDI_PREPARSEDDATA, ppData, ref ppDataSize);
if (result <= 0)
{
Debug.WriteLine("Failed to get raw input pre-parsed data" + result + Marshal.GetLastWin32Error());
@@ -118,6 +118,37 @@
return ppData;
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string GetDeviceName(IntPtr device)
+ {
+ uint deviceNameSize = 256;
+ int result = Win32.Function.GetRawInputDeviceInfoW(device, Win32.Const.RIDI_DEVICENAME, IntPtr.Zero, ref deviceNameSize);
+ if (result != 0)
+ {
+ return string.Empty;
+ }
+
+ IntPtr deviceName = Marshal.AllocHGlobal((int)deviceNameSize * 2); // size is the character count not byte count
+ try
+ {
+ result = Win32.Function.GetRawInputDeviceInfoW(device, Win32.Const.RIDI_DEVICENAME, deviceName, ref deviceNameSize);
+ if (result > 0)
+ {
+ return Marshal.PtrToStringUni(deviceName, result - 1); // -1 for NULL termination
+ }
+
+ return string.Empty;
+ }
+ finally
+ {
+ Marshal.FreeHGlobal(deviceName);
+ }
+ }
+
}
}
\ No newline at end of file
diff -r fb4f80d5cf57 -r 8b2a3da54187 RemoteControlDevice.cs
--- a/RemoteControlDevice.cs Sat Dec 06 01:53:55 2014 +0100
+++ b/RemoteControlDevice.cs Sat Dec 06 02:46:46 2014 +0100
@@ -172,7 +172,7 @@
// remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
// for the vendor defined usage page.
- RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[3];
+ RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5];
int i = 0;
rid[i].usUsagePage = (ushort)Hid.UsagePage.MceRemote;
@@ -192,17 +192,17 @@
rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
rid[i].hwndTarget = aHWND;
- //i++;
- //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControl;
- //rid[i].usUsage = (ushort)Hid.UsageIdGenericDesktop.SystemControl;
- //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
- //rid[i].hwndTarget = aHWND;
+ i++;
+ rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControl;
+ rid[i].usUsage = (ushort)Hid.UsageIdGenericDesktop.SystemControl;
+ rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
+ rid[i].hwndTarget = aHWND;
- //i++;
- //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControl;
- //rid[i].usUsage = (ushort)Hid.UsageIdGenericDesktop.Keyboard;
- //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
- //rid[i].hwndTarget = aHWND;
+ i++;
+ rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControl;
+ rid[i].usUsage = (ushort)Hid.UsageIdGenericDesktop.Keyboard;
+ rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
+ rid[i].hwndTarget = aHWND;
//i++;
//rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControl;
@@ -251,13 +251,22 @@
{
case (int) Keys.Escape:
rcb = RemoteControlButton.Clear;
- break;
+ break;
+ case (int)Keys.Up:
+ rcb = RemoteControlButton.Up;
+ break;
case (int) Keys.Down:
rcb = RemoteControlButton.Down;
break;
case (int) Keys.Left:
rcb = RemoteControlButton.Left;
- break;
+ break;
+ case (int)Keys.Right:
+ rcb = RemoteControlButton.Right;
+ break;
+ case (int)Keys.Enter:
+ rcb = RemoteControlButton.Enter;
+ break;
case (int) Keys.D0:
rcb = RemoteControlButton.Digit0;
break;
@@ -287,20 +296,14 @@
break;
case (int) Keys.D9:
rcb = RemoteControlButton.Digit9;
- break;
- case (int) Keys.Enter:
- rcb = RemoteControlButton.Enter;
- break;
- case (int) Keys.Right:
- rcb = RemoteControlButton.Right;
- break;
- case (int) Keys.Up:
- rcb = RemoteControlButton.Up;
- break;
+ break;
}
- if (this.ButtonPressed != null && rcb != RemoteControlButton.Unknown)
+ if (this.ButtonPressed != null && rcb != RemoteControlButton.Unknown)
+ {
+ Debug.WriteLine("KeyDown: " + rcb.ToString());
this.ButtonPressed(this, new RemoteControlEventArgs(rcb, InputDevice.Key));
+ }
}
@@ -395,6 +398,9 @@
{
return;
}
+
+ //
+ Debug.WriteLine(RawInput.GetDeviceName(rawInput.header.hDevice));
if (rawInput.header.dwType == Const.RIM_TYPEHID) //Check that our raw input is HID
@@ -488,7 +494,12 @@
{
Debug.WriteLine("WM_INPUT source device is Keyboard.");
// do keyboard handling...
-
+ Debug.WriteLine("Type: " + deviceInfo.keyboard.dwType.ToString());
+ Debug.WriteLine("SubType: " + deviceInfo.keyboard.dwSubType.ToString());
+ Debug.WriteLine("Mode: " + deviceInfo.keyboard.dwKeyboardMode.ToString());
+ Debug.WriteLine("Number of function keys: " + deviceInfo.keyboard.dwNumberOfFunctionKeys.ToString());
+ Debug.WriteLine("Number of indicators: " + deviceInfo.keyboard.dwNumberOfIndicators.ToString());
+ Debug.WriteLine("Number of keys total: " + deviceInfo.keyboard.dwNumberOfKeysTotal.ToString());
}
}
finally
diff -r fb4f80d5cf57 -r 8b2a3da54187 Win32RawInput.cs
--- a/Win32RawInput.cs Sat Dec 06 01:53:55 2014 +0100
+++ b/Win32RawInput.cs Sat Dec 06 02:46:46 2014 +0100
@@ -13,7 +13,7 @@
public extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader);
[DllImport("User32.dll", SetLastError=true)]
- public extern static int GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
+ public extern static int GetRawInputDeviceInfoW(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
}