Click here to Skip to main content
12,457,877 members (56,122 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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
 
good
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!.";
            this.Controls.Add(lbl);
        }
  Permalink  
Rate this: bad
 
good
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: 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
  Permalink  

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.160826.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2016
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