Esempio n. 1
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            double xCoordinate = e.X;
            double yCoordinate = e.Y;

            this.MouseXRatio = xCoordinate / this.pictureBox1.Size.Width;
            this.MouseYRatio = yCoordinate / this.pictureBox1.Size.Height;
            if (this.client == null)
            {
                return;
            }
            Console.WriteLine("Up");

            ControlMessage message = new ControlMessage(this.MouseXRatio, this.MouseYRatio);

            if (e.Button == MouseButtons.Left)
            {
                message.clickFlag = ControlMessage.LeftUp;
            }
            else if (e.Button == MouseButtons.Right)
            {
                message.clickFlag = ControlMessage.RightUp;
            }
            sendControlMessage(message);
        }
Esempio n. 2
0
        private void sendControlMessage(ControlMessage con)
        {
            NetworkStream ns;

            byte[] data;
            ns = this.client.GetStream();
            if (ns.CanWrite)
            {
                BinaryFormatter bf = new BinaryFormatter();
                data = con.ToBytes();
                bf.Serialize(ns, data);
                //ns.Write(data, 0, data.Length);
                Console.WriteLine("bytearray sent to server {0}", data.Length);
            }
        }
Esempio n. 3
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (this.client == null)
            {
                return;
            }
            ControlMessage message = new ControlMessage(this.MouseXRatio, this.MouseYRatio);
            byte           KeyCode = (byte)e.KeyCode;

            message.KeyCode      = KeyCode;
            message.KeyBoardFlag = ControlMessage.KeyUp;
            sendControlMessage(message);
            e.Handled          = true;
            e.SuppressKeyPress = true;
        }
Esempio n. 4
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            double xCoordinate = e.X;
            double yCoordinate = e.Y;

            this.MouseXRatio = xCoordinate / this.pictureBox1.Size.Width;
            this.MouseYRatio = yCoordinate / this.pictureBox1.Size.Height;

            if (this.client == null)
            {
                return;
            }
            ControlMessage message = new ControlMessage(this.MouseXRatio, this.MouseYRatio);

            sendControlMessage(message);
        }
Esempio n. 5
0
        public static ControlMessage FromBytes(byte[] buffer)
        {
            ControlMessage retVal = new ControlMessage();

            using (MemoryStream ms = new MemoryStream(buffer))
            {
                BinaryReader br = new BinaryReader(ms);
                retVal.clickFlag    = br.ReadInt32();
                retVal.MouseX       = br.ReadDouble();
                retVal.MouseY       = br.ReadDouble();
                retVal.KeyCode      = br.ReadByte();
                retVal.KeyBoardFlag = br.ReadInt32();
            }

            return(retVal);
        }
Esempio n. 6
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                NetworkStream netStream = this.client.GetStream();
                if (netStream.DataAvailable)
                {
                    Console.WriteLine("data available");
                    byte[] bytes = new byte[this.client.ReceiveBufferSize]; // Reads NetworkStream into a byte buffer. / client.ReceiveBufferSize = 8192
                    //netStream.Read(bytes, 0, (int)client.ReceiveBufferSize); // return anything from 0 to numBytesToRead.
                    //imageFromByteArray(bytes);

                    using (MemoryStream ms = new MemoryStream())
                    {
                        //int read;
                        //do
                        //{
                        //    read = netStream.Read(bytes, 0, bytes.Length);
                        //    Console.WriteLine("data read {0}", read);
                        //    ms.Write(bytes, 0, read);
                        //} while (read == this.client.ReceiveBufferSize);
                        BinaryFormatter bf          = new BinaryFormatter();
                        byte[]          bytesToSend = (byte[])bf.Deserialize(netStream);
                        //byte[] bytesToSend = ms.ToArray();
                        Console.WriteLine("calling imageFromByteArray with bytesTosend {0}", bytesToSend.Length);
                        ControlMessage message    = ControlMessage.FromBytes(bytesToSend);
                        Win32.POINT    p          = new Win32.POINT();
                        Rectangle      resolution = Screen.PrimaryScreen.Bounds;
                        p.x    = Convert.ToInt16(message.MouseX * resolution.Width - this.Location.X) - 8;
                        p.y    = Convert.ToInt16(message.MouseY * resolution.Height - this.Location.Y) - 31;
                        this.p = p;
                        //this.label1.Text = "x:" + p.x + "y: " + p.y;
                        Win32.ClientToScreen(this.Handle, ref p);
                        Win32.SetCursorPos(p.x, p.y);

                        //this.label2.Text = System.Windows.Forms.Control.MousePosition.X.ToString() + "  " + System.Windows.Forms.Control.MousePosition.Y.ToString();
                        switch (message.clickFlag)
                        {
                        case 0:
                            break;

                        case 1:
                            MouseControl.LeftDown();
                            break;

                        case 2:
                            MouseControl.LeftUp();
                            break;

                        case 3:
                            MouseControl.LeftClick();
                            break;

                        case 4:
                            MouseControl.RightDown();
                            break;

                        case 5:
                            MouseControl.RightUp();
                            break;

                        case 6:
                            MouseControl.RightClick();
                            break;

                        default:
                            break;
                        }
                        this.label1.Text = message.KeyBoardFlag.ToString();
                        this.label2.Text = message.KeyCode.ToString();
                        switch (message.KeyBoardFlag)
                        {
                        case 0:
                            break;

                        case 1:
                            KeyBoardControl.KeyUp(message.KeyCode);
                            break;

                        case 2:
                            KeyBoardControl.KeyDown(message.KeyCode);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }