Exemple #1
0
        private void Connect_Click(object sender, EventArgs e)
        {
            WindowsBright winObj = new WindowsBright();

            //MouseManipulator.VirtualMouse.Move(200, 300);
            //System.Windows.Forms.Cursor.Position = new Point(-5, -5);

            Thread t = new Thread(new ThreadStart(ThreadProc));

            t.Start();
        }
        public void BrightSending(Socket listener)
        {
            int computerBrightness = 0;

            Console.WriteLine("Waiting for a BrightSending connection...");
            // Program is suspended while waiting for an incoming connection.
            Socket sendhandler = listener.Accept();

            data = null;
            Console.WriteLine("Connection BrightSending is successss...");
            computerBrightness = WindowsBright.GetBrightness();
            string strBright = "" + computerBrightness;

            Send(sendhandler, strBright);
            //System.Threading.Thread.Sleep(100);
            checkflag = true;
        }
        public void StartListening2()
        {
            short bVal        = 50;
            int   menuItem    = 0;
            int   preVal      = 0;
            bool  controlFlag = false;

            int preX = 0, preY = 0;

            // Data buffer for incoming data.
            byte[] bytes = new Byte[1024];

            Voice         volControl    = new Voice();
            WindowsBright brightControl = new WindowsBright();

            IPAddress ip = IPAddress.Parse(computerIP);
            // Establish the local endpoint for the socket.
            // Dns.GetHostName returns the name of the
            // host running the application.
            IPHostEntry ipHostInfo    = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress   ipAddress     = ipHostInfo.AddressList[0];
            IPEndPoint  localEndPoint = new IPEndPoint(ipAddress, myProt);

            // Create a TCP/IP socket.
            Socket listener = new Socket(AddressFamily.InterNetwork,
                                         SocketType.Stream, ProtocolType.Tcp);

            // Bind the socket to the local endpoint and
            // listen for incoming connections.
            try
            {
                listener.Bind(new IPEndPoint(ip, myProt));
                listener.Listen(10);

                /*---------------------ip bulmak için ------------------------------------*/
                IPsending(listener);
                /*-------------------------------------------------------------------------*/

                /*---------------------key control ------------------------------------*/
                if (checkflag == false)
                {
                    Console.WriteLine("Key Kontrol");
                    KeyControl(listener);
                }
                /*-------------------------------------------------------------------------*/

                /*---------------------brightness control ----------------------------------*/
                BrightSending(listener);
                /*-------------------------------------------------------------------------*/

                // Start listening for connections.
                while (true)
                {
                    Console.WriteLine("Waiting for a connection...");
                    // Program is suspended while waiting for an incoming connection.
                    Socket handler = listener.Accept();
                    data = null;
                    Console.WriteLine("Connection is successss...");
                    // An incoming connection needs to be processed.


                    while (true)
                    {
                        int bytesRec = handler.Receive(bytes);
                        //Console.WriteLine("\n bytesRead  ...  " + bytesRec);

                        data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                        //Console.WriteLine("data  is ... {1}",data);
                        if (data.IndexOf('#') > -1)
                        {
                            break;
                        }
                    }

                    // Show the data on the console.
                    Console.WriteLine("Text received : {0}", data);
                    string temp = data.Substring(4, data.Length - 5);
                    Console.WriteLine("Tmep nedir : {0}", temp);

                    if (temp.Contains("keyboard"))
                    {
                        menuItem = 1; controlFlag = false;
                    }
                    else if (temp.Contains("bright"))
                    {
                        menuItem = 2; controlFlag = false;
                    }
                    else if (temp.Contains("voice"))
                    {
                        menuItem = 3; controlFlag = false;
                    }
                    else if (temp.Contains("mouse"))
                    {
                        menuItem = 4; controlFlag = true;
                    }

                    if (controlFlag == true)
                    {
                        if (menuItem == 1)
                        {
                            try
                            {
                                int m = Int32.Parse(temp);
                                bVal = (short)m;
                                Console.WriteLine("Convert to int text is : {0}", m);
                            }
                            catch (FormatException e)
                            {
                                Console.WriteLine(e.Message);
                            }

                            Keyboard.Keystroke(bVal);
                        }
                        else if (menuItem == 2)
                        {
                            try
                            {
                                int m = Int32.Parse(temp);
                                bVal = (short)m;
                                Console.WriteLine("Convert to int text is : {0}", m);
                            }
                            catch (FormatException e)
                            {
                                Console.WriteLine(e.Message);
                            }

                            brightControl.startup_brightness(bVal);
                        }
                        else if (menuItem == 3)
                        {
                            try
                            {
                                int m = Int32.Parse(temp);
                                bVal = (short)m;
                                Console.WriteLine("Convert to int text is : {0}", m);
                            }
                            catch (FormatException e)
                            {
                                Console.WriteLine(e.Message);
                            }

                            if (bVal > preVal)
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    volControl.btnIncVol_Click();
                                }
                            }
                            else
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    volControl.btnDecVol_Click();
                                }
                            }

                            preVal = bVal;
                        }
                        else if (menuItem == 4)
                        {
                            int    tire = temp.IndexOf('-');
                            string posx = temp.Substring(5, tire - 5);
                            string posy = temp.Substring(tire + 1, temp.Length - (tire + 1));
                            Console.WriteLine(posx + "     " + posy);
                            int posXInt = int.Parse(posx);
                            int posYInt = int.Parse(posy);
                            Console.WriteLine(posXInt + "     " + posYInt);

                            int netX = (posXInt - preX);
                            int netY = (posYInt - preY);

                            MouseManipulator.VirtualMouse.Move(netX, netY);
                            preX = posXInt;
                            preY = posYInt;
                        }
                    }
                    //handler.Shutdown(SocketShutdown.Both);
                    //handler.Close();

                    controlFlag = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.WriteLine("\nPress ENTER to continue...");
            Console.Read();
        }