//here we send data to the mouse void Send_Data_To_MouseAbs() { SetFeatureMouseAbs MouseAbsData = new SetFeatureMouseAbs(); MouseAbsData.ReportID = 1; MouseAbsData.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)); } MouseAbsData.Buttons = btns; //button states are represented by the 3 least significant bits MouseAbsData.X = (UInt16)spnX.Value; MouseAbsData.Y = (UInt16)spnY.Value; //convert struct to buffer byte[] buf = getBytesSFJ(MouseAbsData, Marshal.SizeOf(MouseAbsData)); //send filled buffer to driver HID.SendData(buf, (uint)Marshal.SizeOf(MouseAbsData)); }
//for converting a struct to byte array public byte[] getBytesSFJ(SetFeatureMouseAbs 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); }