static int MouseHookProc(int nCode, int wParam, IntPtr lParam) { if (nCode >= 0) { //把参数lParam在内存中指向的数据转换为MOUSEHOOKSTRUCT结构 MOUSEHOOKSTRUCT mouse = (MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MOUSEHOOKSTRUCT));//鼠标 //这句为了看鼠标的位置 if (wParam == Hooker.WM_RBUTTONDOWN || wParam == Hooker.WM_RBUTTONUP) { //鼠标按下或者释放时候截获 handle.Mouse_RightButtonDown(mouse.pt); } } return(Hooker.CallNextHookEx(Hooker.hMouseHook, nCode, wParam, lParam)); }
/// <summary> /// 代理需要右键完成的功能 /// </summary> /// <param name="action"></param> public static void DelegateCompletingAction(Action action) { Hooker Hooker = new Hooker(); try { Hooker.MouseHookProcedure = new HookProc(MouseHookProc); Hooker.Start(); action(); Hooker.Stop(); } catch (Exception ex) { Hooker.Stop(); } }