/// <summary> /// Deactivates tool from system. /// </summary> /// <returns>false value if it was not found or already deactivated before, otherwise true.</returns> public bool unplug() { if (mhook == IntPtr.Zero) { return(false); } LSender.Send(this, $"mhook - {mhook}", Message.Level.Debug); var ret = NativeMethods.UnhookWindowsHookEx(mhook); mhook = IntPtr.Zero; // the system can also automatically deactivate our hook because of big delay from filters. if (ret == 0) { //throw new WinFuncFailException(); LSender.Send( this, $"whoops, plugin was already deactivated by system or something went wrong - error {Marshal.GetLastWin32Error()}", Message.Level.Error ); } return(true); }
/// <summary> /// Activates tool in system. /// </summary> /// <returns>false value if it was already activated before, otherwise true.</returns> public bool plug() { if (mhook != IntPtr.Zero) { return(false); } llMouseProc = new NativeMethods.LowLevelMouseProc(lowLevelMouseProc); // to protect from GC mhook = NativeMethods.SetWindowsHookEx ( WindowsHookId.WH_MOUSE_LL, llMouseProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().ManifestModule), 0 ); if (mhook == IntPtr.Zero) { throw new WinFuncFailException(); } LSender.Send(this, $"mhook + {mhook}", Message.Level.Debug); return(true); }
public static extern LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam);
public static extern BOOL UnhookWindowsHookEx(HHOOK hhk);
public static extern IntPtr SetWindowsHookEx( [In] WH idHook, [In] HHOOK hookProc, [In] IntPtr hInstance, [In] IntPtr dwThreadId );