private unsafe IntPtr MouseHookProc(User32.HC nCode, IntPtr wparam, IntPtr lparam) { GC.KeepAlive(this); if (nCode == User32.HC.ACTION) { User32.MOUSEHOOKSTRUCT *mhs = (User32.MOUSEHOOKSTRUCT *)lparam; if (mhs is not null) { switch (unchecked ((User32.WM)(long) wparam)) { case User32.WM.LBUTTONDOWN: case User32.WM.MBUTTONDOWN: case User32.WM.RBUTTONDOWN: case User32.WM.NCLBUTTONDOWN: case User32.WM.NCMBUTTONDOWN: case User32.WM.NCRBUTTONDOWN: case User32.WM.MOUSEACTIVATE: if (ProcessMouseDown(mhs->hWnd, mhs->pt.X, mhs->pt.Y)) { return((IntPtr)1); } break; } } } return(User32.CallNextHookEx(new HandleRef(this, _mouseHookHandle), nCode, wparam, lparam)); }
public static IntPtr CallNextHookEx(HandleRef hhook, User32.HC nCode, IntPtr wparam, IntPtr lparam) { IntPtr result = CallNextHookEx(hhook.Handle, nCode, wparam, lparam); GC.KeepAlive(hhook.Wrapper); return(result); }
private unsafe nint MouseHookProc(User32.HC nCode, nint wparam, nint lparam) { if (nCode == User32.HC.ACTION) { var mhs = (User32.MOUSEHOOKSTRUCT *)lparam; if (mhs is not null) { switch ((User32.WM)wparam) { case User32.WM.LBUTTONDOWN: case User32.WM.MBUTTONDOWN: case User32.WM.RBUTTONDOWN: case User32.WM.NCLBUTTONDOWN: case User32.WM.NCMBUTTONDOWN: case User32.WM.NCRBUTTONDOWN: case User32.WM.MOUSEACTIVATE: if (ProcessMouseDown(mhs->hWnd)) { return(1); } break; } } } return(User32.CallNextHookEx(_mouseHookHandle, nCode, wparam, lparam)); }
public virtual IntPtr Callback(User32.HC nCode, IntPtr wparam, IntPtr lparam) { NativeMethods.EVENTMSG eventmsg = Marshal.PtrToStructure <NativeMethods.EVENTMSG>(lparam); if (UnsafeNativeMethods.GetAsyncKeyState((int)Keys.Pause) != 0) { SendKeys.s_stopHook = true; } switch (nCode) { case User32.HC.SKIP: if (!gotNextEvent) { break; } if (SendKeys.events != null && SendKeys.events.Count > 0) { SendKeys.events.Dequeue(); } SendKeys.s_stopHook = SendKeys.events == null || SendKeys.events.Count == 0; break; case User32.HC.GETNEXT: gotNextEvent = true; #if DEBUG Debug.Assert(SendKeys.events != null && SendKeys.events.Count > 0 && !SendKeys.s_stopHook, "HC_GETNEXT when queue is empty!"); #endif SKEvent evt = (SKEvent)SendKeys.events.Peek(); eventmsg.message = evt.wm; eventmsg.paramL = evt.paramL; eventmsg.paramH = evt.paramH; eventmsg.hwnd = evt.hwnd; eventmsg.time = (int)Kernel32.GetTickCount(); Marshal.StructureToPtr(eventmsg, lparam, true); break; default: if (nCode < 0) { User32.CallNextHookEx(SendKeys.s_hhook, nCode, wparam, lparam); } break; } if (SendKeys.s_stopHook) { SendKeys.UninstallJournalingHook(); gotNextEvent = false; } return(IntPtr.Zero); }
public unsafe virtual IntPtr Callback(User32.HC nCode, IntPtr wparam, IntPtr lparam) { User32.EVENTMSG *eventmsg = (User32.EVENTMSG *)lparam; if (User32.GetAsyncKeyState((int)Keys.Pause) != 0) { s_stopHook = true; } switch (nCode) { case User32.HC.SKIP: if (_gotNextEvent) { if (s_events is not null && s_events.Count > 0) { s_events.Dequeue(); } s_stopHook = s_events is null || s_events.Count == 0; break; } break; case User32.HC.GETNEXT: _gotNextEvent = true; Debug.Assert( s_events is not null && s_events.Count > 0 && !s_stopHook, "HC_GETNEXT when queue is empty!"); SKEvent evt = (SKEvent)s_events.Peek(); eventmsg->message = evt.WM; eventmsg->paramL = evt.ParamL; eventmsg->paramH = evt.ParamH; eventmsg->hwnd = evt.HWND; eventmsg->time = Kernel32.GetTickCount(); break; default: if (nCode < 0) { User32.CallNextHookEx(s_hhook, nCode, wparam, lparam); } break; } if (s_stopHook) { UninstallJournalingHook(); _gotNextEvent = false; } return(IntPtr.Zero); }
public virtual nint Callback(User32.HC nCode, nint wparam, nint lparam) { nint result = 0; try { if (_reference.Target is MouseHook hook) { result = hook.MouseHookProc(nCode, wparam, lparam); } } catch (Exception ex) { Debug.Fail(ex.Message); } return(result); }
public virtual IntPtr Callback(User32.HC nCode, IntPtr wparam, IntPtr lparam) { IntPtr ret = IntPtr.Zero; try { MouseHook control = (MouseHook)reference.Target; if (control is not null) { ret = control.MouseHookProc(nCode, wparam, lparam); } } catch { // ignore } return(ret); }
public virtual IntPtr Callback(User32.HC nCode, IntPtr wparam, IntPtr lparam) { IntPtr result = IntPtr.Zero; try { if (_reference.Target is MouseHook hook) { result = hook.MouseHookProc(nCode, wparam, lparam); } } catch (Exception ex) { Debug.Fail(ex.Message); } return(result); }
private unsafe IntPtr MouseHookProc(User32.HC nCode, IntPtr wparam, IntPtr lparam) { if (_isHooked && nCode == User32.HC.ACTION && lparam != IntPtr.Zero) { User32.MOUSEHOOKSTRUCT *mhs = (User32.MOUSEHOOKSTRUCT *)lparam; try { if (ProcessMouseMessage(mhs->hWnd, unchecked ((int)(long)wparam), mhs->pt.X, mhs->pt.Y)) { return((IntPtr)1); } } catch (Exception ex) { _currentAdornerWindow.Capture = false; if (ex != CheckoutException.Canceled) { _currentAdornerWindow._behaviorService.ShowError(ex); } if (ClientUtils.IsCriticalException(ex)) { throw; } } finally { _currentAdornerWindow = null; } } Debug.Assert(_isHooked, "How did we get here when we are disposed?"); return(User32.CallNextHookEx(new HandleRef(this, _mouseHookHandle), nCode, wparam, lparam)); }
private static IntPtr EmptyHookCallback(User32.HC nCode, IntPtr wparam, IntPtr lparam) { return(IntPtr.Zero); }
public static extern IntPtr CallNextHookEx(IntPtr hhook, User32.HC nCode, IntPtr wparam, IntPtr lparam);
public static partial nint CallNextHookEx(IntPtr hhook, User32.HC nCode, nint wparam, nint lparam);