dave_bulac
asked on
How to get MouseClickcoordiantes outside the Form
Hello guys, I am beginner in .Net Programming and need Help. I need a code in c#, that will give me coordinates of a Mouse Click outside the Form in TextBox and then to simulate Mouse Click on that coordinates. Its easy inside the Form but i don't know how to do that outside the Form. I have found articles on msdn but cannot understand how to use it.
ASKER
I have written a code for this but it's not working. it says : "Unable to find an entry point named 'SetcursorPos' in DLL 'user32.dll'." can someone Help me with this ?
code :
[DllImport("user32.dll",En tryPoint=" SetcursorP os")]
private static extern void SetCursorPos(int x, int y);
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const int MOUSE_LEFTDOWN = 0x0202;
private const int MOUSE_LEFTUP = 0x0203;
public void Clicker(int x, int y)
{
SetCursorPos(x, y);
this.Refresh();
Application.DoEvents();
mouse_event(MOUSE_LEFTDOWN ,x,y,0,0);
mouse_event(MOUSE_LEFTUP,x ,y,0,0);
}
code :
[DllImport("user32.dll",En
private static extern void SetCursorPos(int x, int y);
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const int MOUSE_LEFTDOWN = 0x0202;
private const int MOUSE_LEFTUP = 0x0203;
public void Clicker(int x, int y)
{
SetCursorPos(x, y);
this.Refresh();
Application.DoEvents();
mouse_event(MOUSE_LEFTDOWN
mouse_event(MOUSE_LEFTUP,x
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are right, thanks for Help. But what about my main Question ? I have read about low level Mouse hooks but didn'y understand how to get coordinates. I now how to Install Hook, Uninstall and sen information to another Hook. But How to get coordinates i donn't know.
No One knows book or link where will be detailed explained this task ?
No One knows book or link where will be detailed explained this task ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Without more info, you might need:
(1) Low Level Mouse Hook via WH_MOUSE_LL to detect a click anywhere on the screen.
(2) SendInput() API to click the mouse somewhere on the screen.