0

i want to make an application that will automatically move the mouse and click it with just a press of a button in the background.. I'm from Sales and Inventory / HTML Shop website programming and this is my first time making an application that involves control. please help me because i want to push my programming skills. This is what i'm trying to do and my Idea. *i will put an loop counter for the repetition of the moves

1.get the x/y of current cursor and save it to variable named (coordinate) (Point A)

2.Right click it and move lower right (Point B)

3.wait 2 seconds

4.Move back to the first position by using variable (coordinate)

5.End loop repeat.

that's my idea and my algorithm my problem is i don't have any idea how to move a mouse and make it stop.

Cleptus
  • 3,446
  • 4
  • 28
  • 34

2 Answers2

1

In Window Form projects to move a cursor to a specific point on your screen, you can use this static method.

System.Windows.Forms.Cursor.Position = new Point (X,Y);

and to perform a click event you can use this method.

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

public void DoMouseClick()
{
    //Call the imported function with the cursor's current position
    uint X = (uint)System.Windows.Forms.Cursor.Position.X;
    uint Y = (uint)System.Windows.Forms.Cursor.Position.Y;
    mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
Hicham Bouchilkhi
  • 682
  • 10
  • 29
0

You can move mouse writing some function or code like this:

private void MoveCursor()
{
   // Set the Current cursor, move the cursor's Position,
   // and set its clipping rectangle to the form. 

   this.Cursor = new Cursor(Cursor.Current.Handle);
   Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
   Cursor.Clip = new Rectangle(this.Location, this.Size);
}

How To Move mouse in C#

And to find location of any control on your Form you can use the following code

Point locationOnForm = control.FindForm().PointToClient(
    control.Parent.PointToScreen(control.Location));

How to get controls location in Win Forms

Community
  • 1
  • 1
Samvel Petrosov
  • 7,580
  • 2
  • 22
  • 46