Click here to Skip to main content
16,016,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make click on particular (x,y)co-ordinates.. suppose x=10 and y=20 it should make a right click on that points..

If you know how to make click pls help me..

Thank you in advance...

All the best..
Posted

As I understand, you need to simulate a click. The comprehensive way of doing this is Windows API SendInput, which you need to P/Invoke.
See: http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx[^].

—SA
 
Share this answer
 
Comments
Olivier Levrey 11-May-11 3:50am    
I never had to do such a thing and therefore didn't know SendInput. It looks good. My 5.
Sergey Alexandrovich Kryukov 11-May-11 3:55am    
Thank you, Olivier. The fact you did not do such thing is... a good sign. Many our patients try to use it for UI development, probably to show how helpless they are :-). It's only justified when the application field is input event themselves: playing back keyboard/mouse macro, Virtual Keyboards and the like.
--SA
Try:
[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 MakeMouseClick()
    {
    int X = System.Windows.Forms.Cursor.Position.X;
    int Y = System.Windows.Forms.Cursor.Position.Y;
    mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, X, Y, 0, 0);
    }
This causes a Right Click at the cursor position
 
Share this answer
 
Comments
Kim Togo 10-May-11 8:30am    
Good answer, my 5
Sergey Alexandrovich Kryukov 10-May-11 23:53pm    
Griff, please look at this quote: "This function has been superseded. Use SendInput instead.",
http://msdn.microsoft.com/en-us/library/ms646260(v=vs.85).aspx
My 4.

I personally use SendInput for such things, which is not yet deprecated :-)
Please see my answer.
--SA
 
Share this answer
 
Comments
Kim Togo 10-May-11 8:30am    
Good answer, my 5
Sergey Alexandrovich Kryukov 10-May-11 23:54pm    
It is good, my 5, but really comprehensive way is SendInput.
Please see my answer.
--SA
Olivier Levrey 11-May-11 3:51am    
Thanks. I just did a quick google like so many other answers...
Your solution seems a better one.

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