Click here to Skip to main content
13,054,779 members (64,917 online)
Rate this:
Please Sign up or sign in to vote.
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);
Posted 6-Dec-12 8:38am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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!.";
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100