Пример #1
0
        private void Timer_Elapsed(object sender, EventArgs e)
        {
            if (networkStream.DataAvailable)
            {
                int    length   = (int)formatter.Deserialize(networkStream);
                byte[] buffer   = new byte[length];
                int    position = 0;
                while (position < length)
                {
                    position += networkStream.Read(buffer, position, length - position);
                }

                //networkStream.Read(buffer, 0, (int)length);
                MemoryStream mem = new MemoryStream(buffer);
                mem.Position = 0;
                MemoryStream decompressed = new MemoryStream();
                ShortEncoder.Decode(mem, decompressed);
                decompressed.Position = 0;
                screenImg             = encoder.LoadFromStr(decompressed);
                //screenImg = new Bitmap(mem);
                NewFrame.Invoke(screenImg);
            }
            else
            {
                ClientCommand clientCommand = new ClientCommand
                {
                    needFrame  = true,
                    needHeight = height,
                    needWidth  = width
                };
                formatter.Serialize(networkStream, JsonConvert.SerializeObject(clientCommand));
            }
        }
Пример #2
0
        private void Timer_Elapsed(object sender, EventArgs e)
        {
            while (networkStream.DataAvailable)
            {
                string        data    = (string)formatter.Deserialize(networkStream);
                ClientCommand command = JsonConvert.DeserializeObject <ClientCommand>(data);

                if (command.needFrame)
                {
                    sendFrameCommand = command;
                }

                if (command.mouseEvent != 0)
                {
                    MouseEvent(command);
                }

                if (command.moveCursor)
                {
                    MoveCursor(command);
                }

                if (command.pressKey != 0)
                {
                    PressKey(command);
                }
            }
        }
Пример #3
0
        void SendFrame(ClientCommand command, Bitmap screenImg)
        {
            if (encoder == null)
            {
                encoder = new MyEncoder(command.needWidth, command.needHeight);
            }

            Bitmap       small_map = new Bitmap(screenImg, command.needWidth, command.needHeight);
            MemoryStream str       = new MemoryStream();

            encoder.WriteToStr(small_map, str);


            MemoryStream compressed = new MemoryStream();

            str.Position = 0;
            ShortEncoder.Encode(str, compressed);
            compressed.Position = 0;

            lock (tcpLock)
            {
                formatter.Serialize(networkStream, (int)compressed.Length);
                compressed.CopyTo(networkStream);
            }
        }
Пример #4
0
        void MouseEvent(ClientCommand command)
        {
            uint X = (uint)(command.mouseRelativeX * Screen.PrimaryScreen.Bounds.Width) + (uint)Screen.PrimaryScreen.Bounds.X;
            uint Y = (uint)(command.mouseRelativeY * Screen.PrimaryScreen.Bounds.Height) + (uint)Screen.PrimaryScreen.Bounds.Y;

            mouse_event((uint)command.mouseEvent, X, Y, 0, 0);
        }
Пример #5
0
        void MoveCursor(ClientCommand command)
        {
            int X = (int)(command.mouseRelativeX * Screen.PrimaryScreen.Bounds.Width) + (int)Screen.PrimaryScreen.Bounds.X;
            int Y = (int)(command.mouseRelativeY * Screen.PrimaryScreen.Bounds.Height) + (int)Screen.PrimaryScreen.Bounds.Y;

            Cursor.Position = new Point(X, Y);
        }
Пример #6
0
 private void ScreenCapture_NewFrame(object sender, NewFrameEventArgs eventArgs)
 {
     if (sendFrameCommand != null)
     {
         SendFrame(sendFrameCommand, eventArgs.Frame);
         sendFrameCommand = null;
     }
 }
Пример #7
0
        public void PressKey(VirtualKeyCode key, bool keyUp)
        {
            ClientCommand clientCommand = new ClientCommand
            {
                key      = key,
                pressKey = (byte)(keyUp ? 2 : 1)
            };

            formatter.Serialize(networkStream, JsonConvert.SerializeObject(clientCommand));
        }
Пример #8
0
        public void MouseClick(int mouseEvent, float relativeX, float relativeY)
        {
            ClientCommand clientCommand = new ClientCommand
            {
                mouseEvent     = mouseEvent,
                mouseRelativeX = relativeX,
                mouseRelativeY = relativeY
            };

            formatter.Serialize(networkStream, JsonConvert.SerializeObject(clientCommand));
        }
Пример #9
0
        public void MouseMove(float relativeX, float relativeY)
        {
            ClientCommand clientCommand = new ClientCommand
            {
                moveCursor     = true,
                mouseRelativeX = relativeX,
                mouseRelativeY = relativeY
            };

            formatter.Serialize(networkStream, JsonConvert.SerializeObject(clientCommand));
        }
Пример #10
0
 void PressKey(ClientCommand command)
 {
     if (command.pressKey == 1)
     {
         simulator.Keyboard.KeyDown(command.key);
     }
     else
     {
         simulator.Keyboard.KeyUp(command.key);
     }
 }