Exemplo n.º 1
0
        public bool MouseReleaseRel()
        {
            try
            {
                //Set feature data
                SetFeatureMouseRel featureData = new SetFeatureMouseRel();
                featureData.ReportID    = 1;
                featureData.CommandCode = 2;

                //Convert to byte array
                int    featureSize   = Marshal.SizeOf(featureData);
                byte[] featureArray  = new byte[featureSize];
                IntPtr featureIntPtr = Marshal.AllocHGlobal(featureSize);
                Marshal.StructureToPtr(featureData, featureIntPtr, false);
                Marshal.Copy(featureIntPtr, featureArray, 0, featureSize);
                Marshal.FreeHGlobal(featureIntPtr);

                //Send byte array to driver
                return(SetFeature(FileHandle, featureArray));
            }
            catch
            {
                Debug.WriteLine("Failed to release tether mouse.");
                return(false);
            }
        }
Exemplo n.º 2
0
        //here we send data to the mouse
        void Send_Data_To_MouseRel(bool ignoreMove)
        {
            SetFeatureMouseRel MouseRelData = new SetFeatureMouseRel();

            MouseRelData.ReportID    = 1;
            MouseRelData.CommandCode = 2;
            byte btns = 0;

            if (cbLeft.Checked)
            {
                btns = 1;
            }
            ;
            if (cbRight.Checked)
            {
                btns = (byte)(btns | (1 << 1));
            }
            if (cbLeft.Checked)
            {
                btns = (byte)(btns | (1 << 2));
            }
            MouseRelData.Buttons = btns;  //button states are represented by the 3 least significant bits
            if (!ignoreMove)
            {
                MouseRelData.X = (sbyte)spnX.Value;
                MouseRelData.Y = (sbyte)spnY.Value;
            }
            //convert struct to buffer
            byte[] buf = getBytesSFJ(MouseRelData, Marshal.SizeOf(MouseRelData));
            //send filled buffer to driver
            HID.SendData(buf, (uint)Marshal.SizeOf(MouseRelData));
        }
Exemplo n.º 3
0
        //for converting a struct to byte array
        public byte[] getBytesSFJ(SetFeatureMouseRel sfj, int size)
        {
            byte[] arr = new byte[size];
            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(sfj, ptr, false);
            Marshal.Copy(ptr, arr, 0, size);
            Marshal.FreeHGlobal(ptr);
            return(arr);
        }