Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have set my mouse cursor to specific coordinate in my c# form application , but I dont know how to generate click on that.I want to click on the specific coordinate without using mouse.

What I have tried:

I dont know how to do it in c# , there is no built in fn
Posted
Updated 1-Nov-16 2:49am
Comments
phil.o 1-Nov-16 8:21am    
Rather than generating a mouse click that does not exist, why not just executing the event handler that should have been executed if a mouse click would have happened at this place, instead?
Isma Tipu 1-Nov-16 8:40am    
I am using voice so e.g if i say "click" i want to generate click on that ! that is why i said i cant use mouse

 
Share this answer
 
You need to use interop services. This should get you started:

using System.Runtime.InteropServices;

C#
llImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, 
                      int dwData, int dwExtraInfo);

[Flags]
public enum MouseEventFlags
{
    LEFTDOWN = 0x00000002,
    LEFTUP = 0x00000004,
    MIDDLEDOWN = 0x00000020,
    MIDDLEUP = 0x00000040,
    MOVE = 0x00000001,
    ABSOLUTE = 0x00008000,
    RIGHTDOWN = 0x00000008,
    RIGHTUP = 0x00000010
}

public static void LeftClick(int x, int y)
{
    Cursor.Position = new System.Drawing.Point(x, y);
    mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
    mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
}
 
Share this answer
 

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