Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want write a auto keyboard and mouse program first i start with set mouse position and click
i set mouse position out of form but how can i click ?

C#
private void button1_Click(object sender, EventArgs e)
        {

                Cursor.Position = new Point( 500, 500);

        }
Posted

If you are only looking to do this with in the windows form you could try this:

C#
this.OnMouseClick(new MouseEventArgs(MouseButtons.Left,1,500,500,0));


you will be able to pick up the mouse click in here:

C#
private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            Label lbl = new Label();
            lbl.Top = e.Y;
            lbl.Left = e.X;
            lbl.Height = 25;
            lbl.Width = 100;
            lbl.Text = "You clicked here!.";
            this.Controls.Add(lbl);
        }
 
Share this answer
 
I'm not sure you really need to go there.

It looks like you need to simulate mouse click. This is done by raw Windows API SendInput: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

This is how to do in .NET, via P/Invoke: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

Please understand that mouse simulation should not be used for UI development. It can only be used for special purposes, such as keyboard and mouse macro.

—SA
 
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