示例#1
0
        public static RawMouse FromBytes(byte[] bytes, int offset, out int nextByteOffset)
        {
            // Something is wrong, the online documentation says the first field is two bytes.
            // But (when testing real data) everything after the first field is shifted by two bytes, which makes
            // it seem like the first field is actually four bytes.
            //
            // https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawmouse
            // https://github.com/tpn/winsdk-10/blob/master/Include/10.0.10240.0/um/WinUser.h
            ////////

            int dataOffset;

            // should be "offset + 2", but that doesn't work?
            var data = Data.FromBytes(bytes, offset + 4, out dataOffset);

            var rm = new RawMouse()
            {
                Flags        = (RawMouseFlags)(((ushort)bytes[offset + 1] << 8) | (ushort)(bytes[offset])),
                RawMouseData = data,

                RawButtons       = (uint)(((uint)bytes[dataOffset + 3] << 24) | ((uint)bytes[dataOffset + 2] << 16) | ((uint)bytes[dataOffset + 1] << 8) | (uint)(bytes[dataOffset + 0])),
                LastX            = (int)(((int)bytes[dataOffset + 7] << 24) | ((int)bytes[dataOffset + 6] << 16) | ((int)bytes[dataOffset + 5] << 8) | (int)(bytes[dataOffset + 4])),
                LastY            = (int)(((int)bytes[dataOffset + 11] << 24) | ((int)bytes[dataOffset + 10] << 16) | ((int)bytes[dataOffset + 9] << 8) | (int)(bytes[dataOffset + 8])),
                ExtraInformation = (uint)(((uint)bytes[dataOffset + 15] << 24) | ((uint)bytes[dataOffset + 14] << 16) | ((uint)bytes[dataOffset + 13] << 8) | (uint)(bytes[dataOffset + 12])),
            };

            nextByteOffset = dataOffset + 15 + 1;

            return(rm);
        }
示例#2
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);
        }