0

问题标题本身几乎描述了我的整体问题。以下是我到目前为止所做的。

    // the event is registered as following 
     mouseProc = new CallWndRetProc(MouseProc); // get keys
     MouseProcHandle = SetWindowsHookEx(WH_MOUSE_LL, mouseProc, IntPtr.Zero, 0);

     // The callback method
     public static IntPtr MouseProc(int nCode, int wParam, IntPtr lParam)
    {            
        if (wParam == WM_LBUTTONUP && MouseProcHandle != IntPtr.Zero )                
        {

        }

        if (wParam == WM_MOUSEMOVE)
        {
          // Want to get mouse position here 
        }

        return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
    }

有没有可靠的方法来获取鼠标位置?

代码示例将不胜感激谢谢

4

1 回答 1

1

根据codeguru论坛,尤其是pinvoke.net,您可能正在寻找(又是pinvoke.net):

[StructLayout(LayoutKind.Sequential)]
 public struct MSLLHOOKSTRUCT
 {
     public POINT pt;
     public int mouseData; // be careful, this must be ints, not uints (was wrong before I changed it...). regards, cmew.
     public int flags;
     public int time;
     public UIntPtr dwExtraInfo;
 }

然后,当然,您总是可以获得当前坐标。Stackoverflow 上有很多这样的内容。

于 2015-08-28T06:26:30.713 回答