コード例 #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);
        }
コード例 #2
0
ファイル: RawHid.cs プロジェクト: burnsba/BurnsBac.WinApi
        public static RawHid FromBytes(byte[] bytes, int offset, out int nextByteOffset)
        {
            int dwSizeHid = (int)(((int)bytes[offset + 3] << 24) | ((int)bytes[offset + 2] << 16) | ((int)bytes[offset + 1] << 8) | (int)(bytes[offset]));
            int dwCount   = (int)(((int)bytes[offset + 7] << 24) | ((int)bytes[offset + 6] << 16) | ((int)bytes[offset + 5] << 8) | (int)(bytes[offset + 4]));
            int len       = dwSizeHid * dwCount;

            byte[] arrdata = new byte[len];
            Array.Copy(bytes, offset + 8, arrdata, 0, len);

            var hid = new RawHid()
            {
                dwSizeHid = dwSizeHid,
                dwCount   = dwCount,
                bRawData  = arrdata,
            };

            nextByteOffset = offset + 7 + len + 1;

            return(hid);
        }