Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to control the PC cursor by WP7, so I try to use the ManipulationDelta in WP7 that can help me to calculate the difference between he star tap and the end tap
C#
public MainPage()
    {
        InitializeComponent();
        this.ManipulationDelta += new EventHandler<manipulationdeltaeventargs>(MainPage_ManipulationDelta);
        transformG = new TransformGroup();
        translation = new TranslateTransform();
        transformG.Children.Add(translation);
        RenderTransform = transformG; // you see I don't use any transform here because I don't know where I put. If I use the image.RenderTransform  of it will move also for the screen of WP if I put this.RenderTransform, So anyone have a solution

        SenderSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    }

    void MainPage_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        startX = e.ManipulationOrigin.X;
        startY = e.ManipulationOrigin.Y;
        DeltaX = e.DeltaManipulation.Translation.X;
        DeltaY = e.DeltaManipulation.Translation.Y;
        translation.X += e.DeltaManipulation.Translation.X;
        translation.Y += e.DeltaManipulation.Translation.Y;
        EndX = Convert.ToDouble(translation.X);
        EndY = Convert.ToDouble(translation.Y);
    }


I am juste want to send DeltaX and DeltaY to the server to calculate them to the mouse position in the screen, So I write this code

C#
void StartSending()
    {
        while (!stop)

            try
            {
                SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

                byte[] buffer = Encoding.UTF8.GetBytes(DeltaX.ToString() + "/" + DeltaY.ToString());

                socketEventArg.SetBuffer(buffer, 0, buffer.Length);

                SenderSocket.SendToAsync(socketEventArg);
            }
            catch (Exception) { }
    }


I concatenate them in 1 buffer with separate by "/" and in server I use this code to separate

C#
void Receive(byte[] buffer)
    {
        string chaine = "";

        if (SenderSocket != null)
        {
            SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

            socketEventArg.Completed += new EventHandler<socketasynceventargs>(delegate(object s, SocketAsyncEventArgs e)
            {
                if (e.SocketError == SocketError.Success)
                {
                    chaine = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred);
                    chaine.Trim('\0');

                    string[] pos = chaine.Split('/');
                    for (int i = 0; i < pos.Length; i++)
                    {
                        pX = Convert.ToInt32(pos[0]);
                        pY = Convert.ToInt32(pos[1]);

                        this.Cursor = new Cursor(Cursor.Current.Handle);
                        Cursor.Position = new Point(Cursor.Position.X + pX, Cursor.Position.Y + pY);

                    }

                }
                else
                {

                }


            });
            SenderSocket.ReceiveFromAsync(socketEventArg);

        }


Just I want to control the cursor, if you have any other methods so plz help me and I am really grateful.
Posted
Updated 11-Apr-12 10:41am
v2

1 solution

Ok I succeed to develop an app can control PC cursor using WP7 by socket tcp and udp
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900