Exemple #1
0
        public static RawInput FromBytes(byte[] bytes, int offset, out int nextByteOffset)
        {
            RawInput ri;

            int headerOffset;
            int dataOffset;

            var header = RawInputHeader.FromBytes(bytes, offset + 0, out headerOffset);

            if ((int)bytes[offset] == (int)RawInputDeviceType.Mouse)
            {
                ri = new RawInput()
                {
                    Header = header,
                    Data   = new RawInputData()
                    {
                        Mouse = RawMouse.FromBytes(bytes, headerOffset, out dataOffset),
                    },
                };
            }
            else if ((int)bytes[offset] == (int)RawInputDeviceType.Keyboard)
            {
                ri = new RawInput()
                {
                    Header = header,
                    Data   = new RawInputData()
                    {
                        Keyboard = RawKeyboard.FromBytes(bytes, headerOffset, out dataOffset),
                    },
                };
            }
            else if ((int)bytes[offset] == (int)RawInputDeviceType.Hid)
            {
                ri = new RawInput()
                {
                    Header = header,
                    Data   = new RawInputData()
                    {
                        Hid = RawHid.FromBytes(bytes, headerOffset, out dataOffset),
                    },
                };
            }
            else
            {
                throw new NotSupportedException();
            }

            nextByteOffset = dataOffset;

            return(ri);
        }
        public static RawInputHeader FromBytes(byte[] bytes, int offset, out int nextByteOffset)
        {
            var ptrsize = IntPtr.Size;

            var rih = new RawInputHeader()
            {
                dwType  = (RawInputDeviceType)(((uint)bytes[offset + 3] << 24) | ((uint)bytes[offset + 2] << 16) | ((uint)bytes[offset + 1] << 8) | (uint)(bytes[offset + 0])),
                dwSize  = (uint)(((uint)bytes[offset + 7] << 24) | ((uint)bytes[offset + 6] << 16) | ((uint)bytes[offset + 5] << 8) | (uint)(bytes[offset + 4])),
                hDevice = Utility.MakePointer(bytes, 8),
                wParam  = Utility.MakePointer(bytes, 8 + IntPtr.Size),
            };

            nextByteOffset = offset + 7 + IntPtr.Size + IntPtr.Size + 1;

            return(rih);
        }