public IntPtr SetHook() { if (hHook == IntPtr.Zero) { Win32.HookProc keyCallBack = new Win32.HookProc(KeyHookProcedure); hHook = Win32.SetWindowsHookEx( WH_KEYBOARD_LL, keyCallBack, Win32.GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName), 0); gc = GCHandle.Alloc(keyCallBack); } return(hHook); }
//设置Hook public bool SetHook() { if (hHook != IntPtr.Zero) { return(false); } Win32.HookProc mouseCallBack = new Win32.HookProc(MouseHookProcedure); hHook = Win32.SetWindowsHookEx(WH_MOUSE_LL, mouseCallBack, Win32.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0); if (hHook != IntPtr.Zero) { gc = GCHandle.Alloc(mouseCallBack); return(true); } return(false); }