Example #1
0
 private void parseMessage(string buffer)
 {
     //Console.WriteLine("[ [" + buffer + "]");
     String[] commands = buffer.Split(' '); //split incoming message
     if (commands.ElementAt(0).Equals("M")) //mouse movement
     {
         //16 bit è più veloce di 32
         int x = Convert.ToInt16(Double.Parse(commands[1]) * System.Windows.SystemParameters.PrimaryScreenWidth);
         int y = Convert.ToInt16(Double.Parse(commands[2]) * System.Windows.SystemParameters.PrimaryScreenHeight);
         NativeMethods.SetCursorPos(x, y);
     }
     else if (commands.ElementAt(0).ToString().Equals("W")) //scroll
     {
         int scroll = Convert.ToInt32(commands.ElementAt(1).ToString());
         inputSimulator.Mouse.VerticalScroll(scroll);
     }
     else if (commands.ElementAt(0).ToString().Equals("C")) //click
     {
         if (commands.ElementAt(1).ToString().Equals("WM_LBUTTONDOWN"))
         {
             inputSimulator.Mouse.LeftButtonDown();
         }
         else if (commands.ElementAt(1).ToString().Equals("WM_LBUTTONUP"))
         {
             inputSimulator.Mouse.LeftButtonUp();
         }
         else if (commands.ElementAt(1).ToString().Equals("WM_RBUTTONDOWN"))
         {
             inputSimulator.Mouse.RightButtonDown();
         }
         else if (commands.ElementAt(1).ToString().Equals("WM_RBUTTONUP"))
         {
             inputSimulator.Mouse.RightButtonUp();
         }
     }
     else if (commands.ElementAt(0).ToString().Equals("K")) //keyboard
     {
         VirtualKeyCode vk = (VirtualKeyCode)Convert.ToInt32(commands.ElementAt(1).ToString());
         if (commands.ElementAt(2).ToString().Equals("DOWN"))
         {
             inputSimulator.Keyboard.KeyDown(vk); //keydown
         }
         else if (commands.ElementAt(2).ToString().Equals("UP"))
         {
             inputSimulator.Keyboard.KeyUp(vk); //keyup
         }
     }
     else if (commands.ElementAt(0).ToString().Equals("G")) //used as callback for the clipboard
     {
         Console.WriteLine("Ricevuto : GIMME CLIPBOARD");
         ClipboardManager cb             = new ClipboardManager();
         Thread           cbSenderThread = new Thread(() =>
         {
             Thread.CurrentThread.IsBackground = true;
             //mi connetto al volo
             if (this.clientCB != null)
             {
                 this.clientCB.Client.Close();
             }
             this.clientCB = new TcpClient();
             this.clientCB.Connect(((IPEndPoint)this.client.Client.RemoteEndPoint).Address, 9898); //questo è il client che riceve
             cb.sendClipBoardFaster(this.clientCB);
         });
         cbSenderThread.SetApartmentState(ApartmentState.STA);
         cbSenderThread.Start();
         cbSenderThread.Join();
         icon.ShowBalloonTip("Clipboard", "La clipboard è stata trasferita al client!", new Hardcodet.Wpf.TaskbarNotification.BalloonIcon());
     }
 }
        private void parseMessage(string buffer)
        {
            //Console.WriteLine("[ [" + buffer + "]");
            String[] commands = buffer.Split(' '); //split incoming message
            if (commands.ElementAt(0).Equals("M")) //mouse movement
            {
                //16 bit è più veloce di 32
                int x = Convert.ToInt16(Double.Parse(commands[1]) * System.Windows.SystemParameters.PrimaryScreenWidth);
                int y = Convert.ToInt16(Double.Parse(commands[2]) * System.Windows.SystemParameters.PrimaryScreenHeight);
                NativeMethods.SetCursorPos(x, y);
            }
            else if(commands.ElementAt(0).ToString().Equals("W")){ //scroll
                int scroll = Convert.ToInt32(commands.ElementAt(1).ToString());
                inputSimulator.Mouse.VerticalScroll(scroll);
            }
            else if (commands.ElementAt(0).ToString().Equals("C")) //click
            {
                if( commands.ElementAt(1).ToString().Equals("WM_LBUTTONDOWN")){
                    inputSimulator.Mouse.LeftButtonDown();
                }
                else if(commands.ElementAt(1).ToString().Equals("WM_LBUTTONUP")){
                    inputSimulator.Mouse.LeftButtonUp();

                }
                else if(commands.ElementAt(1).ToString().Equals("WM_RBUTTONDOWN")){
                    inputSimulator.Mouse.RightButtonDown();
                }
                else if(commands.ElementAt(1).ToString().Equals("WM_RBUTTONUP")){
                    inputSimulator.Mouse.RightButtonUp();
                }

            }
            else if (commands.ElementAt(0).ToString().Equals("K")) //keyboard
            {
                VirtualKeyCode vk = (VirtualKeyCode)Convert.ToInt32(commands.ElementAt(1).ToString());
                if (commands.ElementAt(2).ToString().Equals("DOWN"))
                {
                    inputSimulator.Keyboard.KeyDown(vk); //keydown
                }
                else if (commands.ElementAt(2).ToString().Equals("UP"))
                {
                    inputSimulator.Keyboard.KeyUp(vk); //keyup
                }
            }
            else if (commands.ElementAt(0).ToString().Equals("G")) //used as callback for the clipboard
            {
                Console.WriteLine("Ricevuto : GIMME CLIPBOARD");
                ClipboardManager cb = new ClipboardManager();
                Thread cbSenderThread = new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    //mi connetto al volo
                    if (this.clientCB != null)
                        this.clientCB.Client.Close();
                    this.clientCB = new TcpClient();
                    this.clientCB.Connect(((IPEndPoint)this.client.Client.RemoteEndPoint).Address, 9898); //questo è il client che riceve
                    cb.sendClipBoardFaster(this.clientCB);
                });
                cbSenderThread.SetApartmentState(ApartmentState.STA);
                cbSenderThread.Start();
                cbSenderThread.Join();
                icon.ShowBalloonTip("Clipboard", "La clipboard è stata trasferita al client!", new Hardcodet.Wpf.TaskbarNotification.BalloonIcon());
            }
        }