问题标题本身很好地描述了我的总体问题。以下是我到目前为止所做的。
// 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);
}
是否有可靠的方法来获取鼠标位置?
代码示例将受到赞赏由于
根据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上有很多。