Link to home
Start Free TrialLog in
Avatar of dave_bulac
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.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

That's not an easy task.  To best help you, how and why are you going to use this code?...there may be other ways to accomplish your goal.

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.
Avatar of dave_bulac
dave_bulac

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",EntryPoint="SetcursorPos")]
        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);
        }
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial