Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
GetRawInputData (user32)
.
C# Signature:
/// <summary>
/// Function to retrieve raw input data.
/// </summary>
/// <param name="hRawInput">Handle to the raw input.</param>
/// <param name="uiCommand">Command to issue when retrieving data.</param>
/// <param name="pData">Raw input data.</param>
/// <param name="pcbSize">Number of bytes in the array.</param>
/// <param name="cbSizeHeader">Size of the header.</param>
/// <returns>0 if successful if pData is null, otherwise number of bytes if pData is not null.</returns>
[DllImport("user32.dll")]
public static extern int GetRawInputData(IntPtr hRawInput, RawInputCommand uiCommand, out RAWINPUT pData, ref int pcbSize, int cbSizeHeader);
or
/// <summary>
/// Function to retrieve raw input data.
/// </summary>
/// <param name="hRawInput">Handle to the raw input.</param>
/// <param name="uiCommand">Command to issue when retrieving data.</param>
/// <param name="pData">Raw input data.</param>
/// <param name="pcbSize">Number of bytes in the array.</param>
/// <param name="cbSizeHeader">Size of the header.</param>
/// <returns>0 if successful if pData is null, otherwise number of bytes if pData is not null.</returns>
[DllImport("user32.dll")]
public static extern int GetRawInputData(IntPtr hRawInput, RawInputCommand uiCommand, byte[] pData, ref int pcbSize, int cbSizeHeader);
VB.NET Signature:
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="GetRawInputData", SetLastError:=True)>
Function GetRawInputData(hRawInput As IntPtr,
uiCommand As UInteger,
ByRef pData As IntPtr,
ByRef pcbSize As IntPtr,
cbSizeHeader As UInteger)
End Function
VB Signature:
Declare Function GetRawInputData Lib "user32.dll" (TODO) As TODO
User-Defined Types:
Alternative Managed API:
Do you know one? Please contribute it!
Enumerations:
Notes:
The VirtualKeys (they're just mapped to the VK_* constants) and WindowsMessages enumeration have been omitted as it's quite lengthy.
RAWINPUT is incompatible with x64. See RAWINPUTHEADER.Device and RAWINPUTHEADER.wParam.
Tips & Tricks:
Please add some!
Sample Code:
protected override void WndProc(ref Message m)
/// <summary>
/// Enumeration containing the type device the raw input is coming from.
/// </summary>
public enum RawInputType
{
if (m.Msg == (int)WindowMessages.RawInput) // WindowMessages.RawInput = 0x00FF (WM_INPUT)
{
RAWINPUT input = new RAWINPUT();
int outSize = 0;
int size = Marshal.SizeOf(typeof(RAWINPUT));
outSize = Win32API.GetRawInputData(m.LParam, RawInputCommand.Input, out input, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER)));
if (outSize != -1)
{
if (input.Header.Type == RawInputType.Mouse)
{
p.X += input.Mouse.LastX;
p.Y += input.Mouse.LastY;
label1.Text = "Mouse: " + p.X.ToString() + "x" + p.Y.ToString() + " " + input.Mouse.ButtonFlags.ToString();
}
}
}
base.WndProc(ref m);
/// <summary>
/// Mouse input.
/// </summary>
Mouse = 0,
/// <summary>
/// Keyboard input.
/// </summary>
Keyboard = 1,
/// <summary>
/// Another device that is not the keyboard or the mouse.
/// </summary>
HID = 2
}
/// <summary>
/// Enumeration containing the flags for raw mouse data.
/// </summary>
[Flags()]
public enum RawMouseFlags
: ushort
{
/// <summary>Relative to the last position.</summary>
MoveRelative = 0,
/// <summary>Absolute positioning.</summary>
MoveAbsolute = 1,
/// <summary>Coordinate data is mapped to a virtual desktop.</summary>
VirtualDesktop = 2,
/// <summary>Attributes for the mouse have changed.</summary>
AttributesChanged = 4
}
/// <summary>
/// Enumeration contanining the command types to issue.
/// </summary>
public enum RawInputCommand
{
/// <summary>
/// Get input data.
/// </summary>
Input = 0x10000003,
/// <summary>
/// Get header data.
/// </summary>
Header = 0x10000005
}
Value types:
/// <summary>
/// Value type for a raw input header.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct RAWINPUTHEADER
{
/// <summary>Type of device the input is coming from.</summary>
public RawInputType Type;
/// <summary>Size of the packet of data.</summary>
public int Size;
/// <summary>Handle to the device sending the data.</summary>
public IntPtr Device;
/// <summary>wParam from the window message.</summary>
public IntPtr wParam;
}
/// <summary>
/// Value type for raw input from a mouse.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct RAWINPUTMOUSE
{
/// <summary>Flags for the event.</summary>
public RawMouseFlags Flags;
/// <summary>If the mouse wheel is moved, this will contain the delta amount.</summary>
public ushort ButtonData;
/// <summary>Flags for the event.</summary>
public RawMouseButtons ButtonFlags;
/// <summary>Raw button data.</summary>
public uint RawButtons;
/// <summary>Relative direction of motion, depending on flags.</summary>
public int LastX;
/// <summary>Relative direction of motion, depending on flags.</summary>
public int LastY;
/// <summary>Extra information.</summary>
public uint ExtraInformation;
}
/// <summary>
/// Value type for raw input from a keyboard.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct RAWINPUTKEYBOARD
{
/// <summary>Scan code for key depression.</summary>
public short MakeCode;
/// <summary>Scan code information.</summary>
public RawKeyboardFlags Flags;
/// <summary>Reserved.</summary>
public short Reserved;
/// <summary>Virtual key code.</summary>
public VirtualKeys VirtualKey;
/// <summary>Corresponding window message.</summary>
public WindowsMessages Message;
/// <summary>Extra information.</summary>
public int ExtraInformation;
}
/// <summary>
/// Value type for raw input from a HID.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct RAWINPUTHID
{
/// <summary>Size of the HID data in bytes.</summary>
public int Size;
/// <summary>Number of HID in Data.</summary>
public int Count;
/// <summary>Data for the HID.</summary>
public IntPtr Data;
}
/// <summary>
/// Value type for raw input.
/// </summary>
[StructLayout(LayoutKind.Explicit)]
public struct RAWINPUT
{
/// <summary>Header for the data.</summary>
[FieldOffset(0)]
public RAWINPUTHEADER Header;
/// <summary>Mouse raw input data.</summary>
[FieldOffset(16)]
public RAWINPUTMOUSE Mouse;
/// <summary>Keyboard raw input data.</summary>
[FieldOffset(16)]
public RAWINPUTKEYBOARD Keyboard;
/// <summary>HID raw input data.</summary>
[FieldOffset(16)]
public RAWINPUTHID HID;
}
Alternative Managed API:
Do you know one? Please contribute it!
Notes:
The VirtualKeys (they're just mapped to the VK_* constants) and WindowsMessages enumeration have been omitted as it's quite lengthy.
RAWINPUT is incompatible with x64. See RAWINPUTHEADER.Device and RAWINPUTHEADER.wParam.
Tips & Tricks:
Please add some!
Sample Code:
protected override void WndProc(ref Message m)
{
if (m.Msg == (int)WindowMessages.RawInput) // WindowMessages.RawInput = 0x00FF (WM_INPUT)
{
RAWINPUT input = new RAWINPUT();
int outSize = 0;
int size = Marshal.SizeOf(typeof(RAWINPUT));
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).