private void HookMessageProcedure() { #pragma warning disable CS0618 // Type or member is obsolete _threadId = (uint)AppDomain.GetCurrentThreadId(); #pragma warning restore CS0618 // Type or member is obsolete _keyboardHookProcedure = new HookProcedure(LowLevelKeyboardProcedure); _keyboardHookHandle = SetWindowsHookEx(HookType.WH_KEYBOARD_LL, _keyboardHookProcedure, UtilInterop.GetModuleHandle(null), 0); var message = new MSG(); while (_keyboardHookRunning) { var result = GetMessage(out message, IntPtr.Zero, 0, 0); if (result == -1) { break; } TranslateMessage(ref message); if (message.message == (int)UtilInterop.WindowMessage.WM_QUIT) { break; } } UnhookWindowsHookEx(_keyboardHookHandle); _keyboardHookHandle = IntPtr.Zero; }
public MouseHook(IntPtr hMod, IntPtr hThread) { _hMod = hMod; _hThread = hThread; _hHook = IntPtr.Zero; _hookProc = new HookProcedure(MouseHookProcedure); }
public void Start() { _mouseHookProcedure = new HookProcedure(LowLevelMouseProcedure); _running = true; _messageThread = new Thread(MessageThreadRoutine); _messageThread.Start(); }
// Token: 0x06000317 RID: 791 RVA: 0x0000F43C File Offset: 0x0000D63C private static HookResult HookGlobal(int hookId, Callback callback) { HookProcedure hookProcedure = (int code, IntPtr param, IntPtr lParam) => HookHelper.HookProcedure(code, param, lParam, callback); HookProcedureHandle hookProcedureHandle = HookNativeMethods.SetWindowsHookEx(hookId, hookProcedure, Process.GetCurrentProcess().MainModule.BaseAddress, 0); if (hookProcedureHandle.IsInvalid) { HookHelper.ThrowLastUnmanagedErrorAsException(); } return(new HookResult(hookProcedureHandle, hookProcedure)); }
// Token: 0x06000316 RID: 790 RVA: 0x0000F3EC File Offset: 0x0000D5EC private static HookResult HookApp(int hookId, Callback callback) { HookProcedure hookProcedure = (int code, IntPtr param, IntPtr lParam) => HookHelper.HookProcedure(code, param, lParam, callback); HookProcedureHandle hookProcedureHandle = HookNativeMethods.SetWindowsHookEx(hookId, hookProcedure, IntPtr.Zero, ThreadNativeMethods.GetCurrentThreadId()); if (hookProcedureHandle.IsInvalid) { HookHelper.ThrowLastUnmanagedErrorAsException(); } return(new HookResult(hookProcedureHandle, hookProcedure)); }
public InputInterceptor() { try { // Store delegate to prevent it's been garbage collected hookProcedure = LowLevelHookProc; thread.Start(MessagePumpInit); } catch { Dispose(); throw; } }
private static HookResult HookGlobal(int hookId, Callback callback) { _globalHookProc = (code, param, lParam) => HookProcedure(code, param, lParam, callback); var hookHandle = HookNativeMethods.SetWindowsHookEx( hookId, _globalHookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0); if (hookHandle.IsInvalid) { ThrowLastUnmanagedErrorAsException(); } return new HookResult(hookHandle, _globalHookProc); }
private static HookResult HookApp(int hookId, Callback callback) { _appHookProc = (code, param, lParam) => HookProcedure(code, param, lParam, callback); var hookHandle = HookNativeMethods.SetWindowsHookEx( hookId, _appHookProc, IntPtr.Zero, ThreadNativeMethods.GetCurrentThreadId()); if (hookHandle.IsInvalid) { ThrowLastUnmanagedErrorAsException(); } return new HookResult(hookHandle, _appHookProc); }
private static HookResult HookApp(int hookId, Callback callback) { _appHookProc = (code, param, lParam) => HookProcedure(code, param, lParam, callback); var hookHandle = HookNativeMethods.SetWindowsHookEx( hookId, _appHookProc, IntPtr.Zero, ThreadNativeMethods.GetCurrentThreadId()); if (hookHandle.IsInvalid) { ThrowLastUnmanagedErrorAsException(); } return(new HookResult(hookHandle, _appHookProc)); }
private static HookResult HookGlobal(int hookId, Callback callback) { _globalHookProc = (code, param, lParam) => HookProcedure(code, param, lParam, callback); var hookHandle = HookNativeMethods.SetWindowsHookEx( hookId, _globalHookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0); if (hookHandle.IsInvalid) { ThrowLastUnmanagedErrorAsException(); } return(new HookResult(hookHandle, _globalHookProc)); }
public static HookHandle Create(HookType idHook, HookProcedure lpfn, IntPtr hMod, int dwThreadId) { var FunctionPointer = GCHandle.Alloc(lpfn); var ret = HookNativeMethods.SetWindowsHookEx(idHook, lpfn, hMod, dwThreadId); if (ret.IsInvalid) { FunctionPointer.Free(); ThrowLastUnmanagedErrorAsException(); } else { ret.FunctionPointer = FunctionPointer; } return(ret); }
protected LowLevelHook(HookType type) { _type = type; _hHook = IntPtr.Zero; _internalCallback = InternalCallback; }
/// <summary> /// Make sure <param name="procedure">procedure</param> is not cleaned up by the garbage collector. Otherwise the garbage collector will clean up your hook delegate eventually, resulting in your code throwing a System.NullReferenceException. /// /// </summary> /// <param name="procedure"></param> /// <returns></returns> public static IntPtr HookGlobal(HookProcedure procedure) { return(HookManager.GlobalHook(HookType.KeyboardGlobal, procedure)); }
internal extern static IntPtr SetWindowsHookEx(Int32 idHook, HookProcedure hookProc, IntPtr hMod, IntPtr hThread);
private static extern IntPtr SetWindowsHookEx( HookType type, HookProcedure lpfn, IntPtr hMod, int dwThreadId);
public HookResult(HookProcedureHandle handle, HookProcedure procedure) { m_Handle = handle; m_Procedure = procedure; }
/// <summary> /// Make sure <param name="procedure">procedure</param> is not cleaned up by the garbage collector. Otherwise the garbage collector will clean up your hook delegate eventually, resulting in your code throwing a System.NullReferenceException. /// /// </summary> /// <param name="procedure"></param> /// <returns></returns> public static IntPtr GlobalHook(HookType type, HookProcedure procedure) { return(User32.SetWindowsHookEx((int)type, procedure, IntPtr.Zero, 0)); }
public static extern IntPtr SetWindowsHookEx(HookType hookType, HookProcedure hookProcedure, IntPtr moduleHandle, UInt32 threadID);
internal static extern HookProcedureHandle SetWindowsHookEx( int idHook, HookProcedure lpfn, IntPtr hMod, int dwThreadId);
public Win32() { hookProcedure = new HookProcedure(ProcessHook); }
static extern IntPtr SetWindowsHookEx(int idHook, HookProcedure callback, IntPtr hInstance, uint theardID);
private static IntPtr SetHook(HookProcedure procedure) { using (Process process = Process.GetCurrentProcess()) using (ProcessModule module = process.MainModule) return(SetWindowsHookEx(WH_KEYBOARD_LL, procedure, GetModuleHandle(module.ModuleName), 0)); }
public static extern IntPtr SetWindowsHookEx(int idHook, HookProcedure lpfn, IntPtr hMod, uint dwThreadId);
public static extern HookHandle SetWindowsHookEx( HookType idHook, HookProcedure lpfn, IntPtr hMod, int dwThreadId);