1

Does anyone knows how to perform a mouse click on a specific point of the desktop? I need a application to perform mouse click on another's application button localized in a specific place on desktop.

AlinaM
  • 85
  • 1
  • 11

2 Answers2

1

This works in WinForms

[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;


 public void DoMouseClick()   {
     //Call the imported function with the cursor's current position
     int X = Cursor.Position.X;
     int Y = Cursor.Position.Y;
     mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);

}

From http://www.gamedev.net/topic/321029-how-to-simulate-a-mouse-click-in-c/

Seth Kitchen
  • 1,526
  • 19
  • 53
  • Adding [someone else's answer](http://stackoverflow.com/questions/2416748/how-to-simulate-mouse-click-in-c) [(2)](http://www.gamedev.net/topic/321029-how-to-simulate-a-mouse-click-in-c/) without attribution is plagiarism. – spender Sep 17 '15 at 14:07
  • Actually I got it from this site: http://www.gamedev.net/topic/321029-how-to-simulate-a-mouse-click-in-c/ – Seth Kitchen Sep 17 '15 at 14:16
  • SO tells me that if you edit this into your answer, I can remove my downvote. – spender Sep 17 '15 at 14:39
0

You may look into Coded UI. It's main purpose is for performing UI tests on applications and supports programmatic access to a variety of different application frameworks (WPF, WinForms, VB, etc).

BryanJ
  • 8,485
  • 1
  • 42
  • 61