More cleanup and re-org.
2 using System.Runtime.InteropServices;
7 static partial class Function
9 [DllImport("User32.dll", SetLastError = true)]
10 public extern static bool RegisterRawInputDevices(RAWINPUTDEVICE[] pRawInputDevice, uint uiNumDevices, uint cbSize);
12 [DllImport("User32.dll", SetLastError = true)]
13 public extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader);
15 [DllImport("User32.dll", SetLastError=true)]
16 public extern static int GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
19 static partial class Const
22 /// GetRawInputDeviceInfo pData points to a string that contains the device name.
24 public const uint RIDI_DEVICENAME = 0x20000007;
26 /// GetRawInputDeviceInfo For this uiCommand only, the value in pcbSize is the character count (not the byte count).
28 public const uint RIDI_DEVICEINFO = 0x2000000b;
30 /// GetRawInputDeviceInfo pData points to an RID_DEVICE_INFO structure.
32 public const uint RIDI_PREPARSEDDATA = 0x20000005;
36 /// Data comes from a mouse.
38 public const uint RIM_TYPEMOUSE = 0;
40 /// Data comes from a keyboard.
42 public const uint RIM_TYPEKEYBOARD = 1;
44 /// Data comes from an HID that is not a keyboard or a mouse.
46 public const uint RIM_TYPEHID = 2;
48 public const int RID_INPUT = 0x10000003;
49 public const int RID_HEADER = 0x10000005;
55 [StructLayout(LayoutKind.Sequential, Pack = 1)]
56 internal struct RAWINPUTDEVICE
58 [MarshalAs(UnmanagedType.U2)]
59 public ushort usUsagePage;
60 [MarshalAs(UnmanagedType.U2)]
61 public ushort usUsage;
62 [MarshalAs(UnmanagedType.U4)]
64 public IntPtr hwndTarget;
68 [StructLayout(LayoutKind.Sequential, Pack = 1)]
69 internal struct RAWINPUTHEADER
71 [MarshalAs(UnmanagedType.U4)]
73 [MarshalAs(UnmanagedType.U4)]
75 public IntPtr hDevice;
76 [MarshalAs(UnmanagedType.U4)]
81 [StructLayout(LayoutKind.Sequential, Pack = 1)]
82 internal struct RAWHID
84 [MarshalAs(UnmanagedType.U4)]
86 [MarshalAs(UnmanagedType.U4)]
93 [StructLayout(LayoutKind.Sequential, Pack = 1)]
94 internal struct BUTTONSSTR
96 [MarshalAs(UnmanagedType.U2)]
97 public ushort usButtonFlags;
98 [MarshalAs(UnmanagedType.U2)]
99 public ushort usButtonData;
103 [StructLayout(LayoutKind.Explicit, Pack = 1)]
104 internal struct RAWMOUSE
106 [MarshalAs(UnmanagedType.U2)]
108 public ushort usFlags;
109 [MarshalAs(UnmanagedType.U4)]
111 public uint ulButtons;
113 public BUTTONSSTR buttonsStr;
114 [MarshalAs(UnmanagedType.U4)]
116 public uint ulRawButtons;
117 [MarshalAs(UnmanagedType.U4)]
120 [MarshalAs(UnmanagedType.U4)]
123 [MarshalAs(UnmanagedType.U4)]
125 public uint ulExtraInformation;
128 [StructLayout(LayoutKind.Sequential, Pack = 1)]
129 internal struct RAWKEYBOARD
131 [MarshalAs(UnmanagedType.U2)]
132 public ushort MakeCode;
133 [MarshalAs(UnmanagedType.U2)]
135 [MarshalAs(UnmanagedType.U2)]
136 public ushort Reserved;
137 [MarshalAs(UnmanagedType.U2)]
139 [MarshalAs(UnmanagedType.U4)]
141 [MarshalAs(UnmanagedType.U4)]
142 public uint ExtraInformation;
146 [StructLayout(LayoutKind.Explicit, Pack = 1)]
147 internal struct RAWINPUT
150 public RAWINPUTHEADER header;
152 public RAWMOUSE mouse;
154 public RAWKEYBOARD keyboard;
160 [StructLayout(LayoutKind.Sequential, Pack = 1)]
161 internal struct RID_DEVICE_INFO_MOUSE
164 public uint dwNumberOfButtons;
165 public uint dwSampleRate;
166 public bool fHasHorizontalWheel;
170 [StructLayout(LayoutKind.Sequential, Pack = 1)]
171 internal struct RID_DEVICE_INFO_KEYBOARD
174 public uint dwSubType;
175 public uint dwKeyboardMode;
176 public uint dwNumberOfFunctionKeys;
177 public uint dwNumberOfIndicators;
178 public uint dwNumberOfKeysTotal;
181 [StructLayout(LayoutKind.Sequential, Pack = 1)]
182 internal struct RID_DEVICE_INFO_HID
184 public uint dwVendorId;
185 public uint dwProductId;
186 public uint dwVersionNumber;
187 public ushort usUsagePage;
188 public ushort usUsage;
191 [StructLayout(LayoutKind.Explicit, Pack = 1)]
192 internal struct RID_DEVICE_INFO
199 public RID_DEVICE_INFO_MOUSE mouse;
201 public RID_DEVICE_INFO_KEYBOARD keyboard;
203 public RID_DEVICE_INFO_HID hid;