Click here to Skip to main content
15,944,136 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 ?

private void button1_Click(object sender, EventArgs e)

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


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

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

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

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!.";
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:[^].

This is how to do in .NET, via P/Invoke:[^].

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.

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