C #: How to get my mouse coordinates when left / right click?

How to get the coordinates of my mouse when clicking the left / right mouse button?

I use a low-level mouse hook and can get the current position of my cursor, but I would like to get the position when any mouse button was pressed.

How can i do this?

+3
source share
6 answers

http://www.codeproject.com/KB/system/globalsystemhook.aspx - this solved my problem. Used DLL from the demo project and was able to get the coordinates.

0
source

MouseDown MouseEventArgs, MouseEventArgs.Location?

+3

GetMessagePos() WM_LBUTTONDOWN, , . , mousehook. proc.

" GetMessagePos , GetMessage."

, ?

0

MouseHook:

public static int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
    //Marshall the data from the callback.
    MouseHookStruct MyMouseHookStruct = 
         (MouseHookStruct) Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));

    if (nCode >= 0)
    {
        int xcoord = MyMouseHookStruct.pt.x;
        int ycoord = MyMouseHookStruct.pt.y;
    }

    return CallNextHookEx(hHook, nCode, wParam, lParam); 
}

.

0

wParam MouseHook WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP .., , .

0
source

http://www.codeproject.com/KB/vb-interop/MouseHunter.aspx - I found this little charming information. Sadly, Visual Studio 2008 will not accept a DLL that has been precompiled, and I cannot force Visual Basic 6 to install an attempt to recompile it on my machine.

0
source

Source: https://habr.com/ru/post/1728541/


All Articles