static unsafe RawInputData ParseRawInputBufferItem(byte *ptr) { var header = *(RawInputHeader *)ptr; var headerSize = MarshalExtensions.SizeOf <RawInputHeader>(); var dataPtr = ptr + headerSize; if (IntPtr.Size == 4 && Environment.Is64BitOperatingSystem) { dataPtr += 8; } switch (header.Type) { case RawInputDeviceType.Mouse: return(new RawInputMouseData(header, *(RawMouse *)dataPtr)); case RawInputDeviceType.Keyboard: return(new RawInputKeyboardData(header, *(RawKeyboard *)dataPtr)); case RawInputDeviceType.Hid: return(RawInputHidData.Create(header, RawHid.FromPointer(dataPtr))); default: throw new ArgumentException(); } }
static unsafe RawInputData ParseRawInputBufferItem(byte *ptr) { var header = *(RawInputHeader *)ptr; var headerSize = MarshalEx.SizeOf <RawInputHeader>(); var dataPtr = ptr + headerSize; // RAWINPUT structure must be aligned by 8 bytes on WOW64 // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputbuffer#remarks if (EnvironmentEx.Is64BitProcess && EnvironmentEx.Is64BitOperatingSystem) { dataPtr += 8; } switch (header.Type) { case RawInputDeviceType.Mouse: return(new RawInputMouseData(header, *(RawMouse *)dataPtr)); case RawInputDeviceType.Keyboard: return(new RawInputKeyboardData(header, *(RawKeyboard *)dataPtr)); case RawInputDeviceType.Hid: return(RawInputHidData.Create(header, RawHid.FromPointer(dataPtr))); default: throw new ArgumentException(); } }