//Hook回调函数 private int MouseHookProcedure(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && MHookEvent != null) { MSLLHOOTSTRUCT stMSLL = (MSLLHOOTSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOTSTRUCT)); ButtonStatus btnStatus = ButtonStatus.None; if (wParam == (IntPtr)WM_LBUTTONDOWN) { btnStatus = ButtonStatus.LeftDown; } else if (wParam == (IntPtr)WM_LBUTTONUP) { btnStatus = ButtonStatus.LeftUp; } else if (wParam == (IntPtr)WM_RBUTTONDOWN) { btnStatus = ButtonStatus.RightDown; } else if (wParam == (IntPtr)WM_RBUTTONUP) { btnStatus = ButtonStatus.RightUp; } MHookEvent(this, new MHookEventArgs(btnStatus, stMSLL.pt.X, stMSLL.pt.Y)); } return(Win32.CallNextHookEx(hHook, nCode, wParam, lParam)); }
private int KeyHookProcedure(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && KeyHookEvent != null) { KeyInfoStruct inputInfo = (KeyInfoStruct)Marshal.PtrToStructure(lParam, typeof(KeyInfoStruct)); if (wParam == (IntPtr)WM_KEYDOWN) //如果按键按下 { this.OnKeyHookEvent(new KeyHookEventArgs(inputInfo.vkCode)); } } return(Win32.CallNextHookEx(hHook, nCode, wParam, lParam));//继续传递消息 }