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(); } }
public RawInputDigitizerData(RawInputHeader header, RawHid hid) : base(header, hid) { var digitizer = (RawInputDigitizer)Device; var contactButtonStates = ButtonSetStates.SelectMany(x => x).Where(x => x.Button.LinkUsageAndPage != digitizer.UsageAndPage).ToLookup(x => x.Button.LinkCollection); var contactValueStates = ValueSetStates.SelectMany(x => x).Where(x => x.Value.LinkUsageAndPage != digitizer.UsageAndPage).ToLookup(x => x.Value.LinkCollection); var contactCount = ValueSetStates.SelectMany(x => x).FirstOrDefault(x => x.Value.LinkUsageAndPage == digitizer.UsageAndPage && x.Value.UsageAndPage == RawInputDigitizer.UsageContactCount)?.CurrentValue ?? 1; Contacts = contactButtonStates.Select(buttonStates => new RawInputDigitizerContact(buttonStates, contactValueStates[buttonStates.Key])) .Take(contactCount) .ToArray(); }
public static unsafe byte[] GetHIDRawData(ref RawHid rawHid) { var byteCount = rawHid.dwCount * rawHid.dwSizeHid; var result = new byte[byteCount]; fixed(byte *dest = result) { fixed(int *src = &rawHid.bRawData) { Unsafe.CopyBlockUnaligned(dest, src, byteCount); } } return(result); }
protected RawInputHidData(RawInputHeader header, RawHid hid) : base(header) =>