/// <summary> /// Class constructor /// </summary> /// <param name="hWnd"> /// Handle to the window we are going to hook into /// </param> /// <param name="hook"> /// Determines what type of hook this is /// </param> public WindowsHook(IntPtr hWnd, HookType hook) { this.hWnd = hWnd; this.hookType = hook; this.hookDelegate = new HookDelegate(this.CoreHookProc); }
public WindowsHook(IntPtr hWnd, HookType hook, HookDelegate proc) { this.hWnd = hWnd; this.hookType = hook; this.hookDelegate = proc; }
public Hooker(CapslockIndicator capslockIndicator) { this.capslockIndicator = capslockIndicator; keyBoardDelegate = KeyboardHookDelegate; keyBoardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, keyBoardDelegate, IntPtr.Zero, 0); }
public void Start() { var hookReadyEvent = new AutoResetEvent(false); var hookThread = new Thread(() => { var sleepEvent = new AutoResetEvent(false); var process = System.Diagnostics.Process.GetCurrentProcess(); var module = process.MainModule; var moduleHandle = Kernel32.GetModuleHandle(module.ModuleName); // IMPORTANT: // Ensures that the hook delegate does not get garbage collected prematurely, as it will be passed to unmanaged code. // Not doing so will result in a <c>CallbackOnCollectedDelegate</c> error and subsequent application crash! hookDelegate = new HookDelegate(LowLevelKeyboardProc); handle = User32.SetWindowsHookEx(HookType.WH_KEYBOARD_LL, hookDelegate, moduleHandle, 0); hookReadyEvent.Set(); while (true) { sleepEvent.WaitOne(); } }); hookThread.SetApartmentState(ApartmentState.STA); hookThread.IsBackground = true; hookThread.Start(); hookReadyEvent.WaitOne(); }
public WindowsHook(IntPtr hWnd, HookType hook, HookDelegate proc) { this.hHook = IntPtr.Zero; this.hWnd = IntPtr.Zero; this.hWnd = hWnd; this.hookType = hook; this.hookDelegate = proc; }
public WindowsHook(IntPtr hWnd, HookType hook) { this.hHook = IntPtr.Zero; this.hWnd = IntPtr.Zero; this.hWnd = hWnd; this.hookType = hook; this.hookDelegate = new HookDelegate(this.CoreHookProc); }
/// <summary> /// Stop the IR Server plugin. /// </summary> public override void Stop() { UnhookWindowsHookEx(_hookHandle); _hookHandle = IntPtr.Zero; _hookDelegate = null; _libPtr = IntPtr.Zero; }
/// <summary> /// Creates a new <see cref="EventClass{T}"/>. /// </summary> /// <param name="context">Current <see cref="ScriptContext"/>.</param> /// <param name="eventName">Name of the CLR event.</param> /// <param name="addMethod">Delegate pointing to the event's add method (may be <B>null</B>).</param> /// <param name="removeMethod">Delegate pointing to the event's remove method (may be <B>null</B>).</param> /// <remarks> /// At least one of <paramref name="addMethod"/> and <paramref name="removeMethod"/> must be non-<B>null</B>. /// </remarks> private EventClass(ScriptContext /*!*/ context, string /*!*/ eventName, HookDelegate addMethod, HookDelegate removeMethod) : this(context, true) { Debug.Assert(addMethod != null || removeMethod != null); this.eventName = eventName; this.addMethod = addMethod; this.removeMethod = removeMethod; }
public static EventClass <T> Wrap(ScriptContext /*!*/ context, string eventName, HookDelegate addMethod, HookDelegate removeMethod) { // cache the result? // it would support things like: // $x = $y->EventName->runtimeField = "test"; // echo $y->EventName->runtimeField; return(new EventClass <T>(context, eventName, addMethod, removeMethod)); }
public static void AddHook(string hookName, HookDelegate hookFunc) { HookDelegate _delegate; if (!HookActions.TryGetValue(hookName, out _delegate)) { HookActions[hookName] = null; } HookActions[hookName] += hookFunc; }
public ImGuiXNAFormsHook(IntPtr handleForm, HookDelegate hook) { HandleForm = handleForm; Hook = hook; _WndProcHook = WndProcHook; HandleHook = Win32.SetWindowsHookEx( 4, _WndProcHook, IntPtr.Zero, Win32.GetWindowThreadProcessId(HandleForm, IntPtr.Zero) ); }
public TimerBasedInputSource() { timer = new DispatcherTimer(); timer.Interval = 100.Milliseconds(); timer.Tick += TimerTick; timer.Start(); keyBoardDelegate = KeyboardHookDelegate; mouseDelegate = MouseHookDelegate; keyBoardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, keyBoardDelegate, IntPtr.Zero, 0); mouseHandle = SetWindowsHookEx(WH_MOUSE_LL, mouseDelegate, IntPtr.Zero, 0); }
public XNAFormsHook(IntPtr handleForm, HookDelegate hook) { HandleForm = handleForm; Hook = hook; _WndProcHook = WndProcHook; HandleHook = Win32.SetWindowsHookEx( Win32.HookType.WH_GETMESSAGE, // Was WH_CALLWNDPROC in ImGuiXNA _WndProcHook, IntPtr.Zero, Win32.GetWindowThreadProcessId(HandleForm, IntPtr.Zero) ); }
internal void Attach() { var process = System.Diagnostics.Process.GetCurrentProcess(); var module = process.MainModule; var moduleHandle = Kernel32.GetModuleHandle(module.ModuleName); // IMPORTANT: // Ensures that the hook delegate does not get garbage collected prematurely, as it will be passed to unmanaged code. // Not doing so will result in a <c>CallbackOnCollectedDelegate</c> error and subsequent application crash! hookDelegate = new HookDelegate(LowLevelKeyboardProc); handle = User32.SetWindowsHookEx(HookType.WH_KEYBOARD_LL, hookDelegate, moduleHandle, 0); }
public void Hook() { if (this.hook != IntPtr.Zero) { return; } this.hookDelegate = this.MouseHookProc; var threadId = GetCurrentThreadId(); this.hook = SetWindowsHookEx(WH_CALLWNDPROC, this.hookDelegate, IntPtr.Zero, threadId); if (this.hook != IntPtr.Zero) { Application.ApplicationExit += (sender, args) => this.Unhook(); return; } var errorCode = Marshal.GetLastWin32Error(); throw new Win32Exception(errorCode); }
public static extern IntPtr SetWindowsHookEx(Int32 idHook, HookDelegate lpfn, IntPtr hmod, Int32 dwThreadId);
public ModalWindow() { InitializeComponent(); mouseDelegate = MouseHookDelegate; mouseHandle = SetWindowsHookEx(WH_MOUSE_LL, mouseDelegate, IntPtr.Zero, 0); }
public static void RemoveHook(string hookName, HookDelegate hookFunc) { HookActions[hookName] -= hookFunc; }
internal static extern int SetWindowsHookEx(int idHook, HookDelegate lpfn, IntPtr hMod, int dwThreadId);
public KeyboardHook() { keyBoardDelegate = KeyboardHookDelegate; keyBoardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, keyBoardDelegate, IntPtr.Zero, 0); }
/* * Method: Start() * Summary: Hooks the keyboard to the program and begins recording each key press */ public void Start() { // If there is still a hook attached, throw an exception // This had to be included as I was having huge problems as a result of multiple hook/unhook operations in a single execution // This line ensures that the program will not try set another hook if one already exists if (keyboardDelegate != null) throw new InvalidOperationException("Cannot hook more than once"); if (mouseDelegate != null) throw new InvalidOperationException("Cannot hook more than once"); IntPtr hInstance = LoadLibrary("User32"); // Loads the User32 library and returns the module value, assigning it to the hInstance variable keyboardDelegate = new HookDelegate(onKeyActivity); // Initialises the keyboardDelegate using the onKeyActivity method mouseDelegate = new HookDelegate(onMouseActivity); // Installs the hook to the keyboard using the following parameters // WH_KEYBOARD_LL stores the value 13, which is the code for the keyboard hook type // keyboardDelegate is the variable, of type HookDelegate, which passes a reference to the onKeyActivity method // hInstance stores the handle of the module thread // 0 is the thread ID. It tells the hook to listen to the activity of all threads, not just the thead containing the program itself // The call returns an IntPtr which is stored in the hookId variable. This is the ID of the hook which is later used to remove the hook. keyboardHookId = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardDelegate, hInstance, 0); mouseHookId = SetWindowsHookEx(WH_MOUSE_LL, mouseDelegate, hInstance, 0); watch.Start(); // Starts the timer }
partial void InitializeNativeHooks() { hook = OnMouseEventProc; }
private static extern int SetWindowsHookEx(int hookId, HookDelegate function, IntPtr instance, int threadId);
public AssetBundleNamer(HookDelegate hookAction) { this.hookAction = hookAction; }
public KeyboardInputEventHelper() { _keyBoardDelegate = KeyboardHookDelegate; _keyBoardHandle = SetWindowsHookEx( WH_KEYBOARD_LL, _keyBoardDelegate, IntPtr.Zero, 0); }
/// <summary> /// Start the IR Server plugin. /// </summary> public override void Start() { _hookDelegate = InternalHookDelegate; _libPtr = LoadLibrary("User32"); _hookHandle = SetWindowsHookEx(HookType.WH_KEYBOARD_LL, _hookDelegate, _libPtr, 0); }
public static extern IntPtr SetWindowsHookEx(HookType code, HookDelegate func, IntPtr hInstance, int threadID);
private static extern IntPtr SetWindowsHookEx(int hookId, HookDelegate hookProc, IntPtr hookInstance, uint threadId);
internal static extern IntPtr SetWindowsHookEx(HookType hookType, HookDelegate lpfn, IntPtr hMod, uint dwThreadId);
private static extern IntPtr SetWindowsHookEx(int idHook, HookDelegate lpfn, IntPtr hmod, int dwThreadId);
public static extern IntPtr SetWindowsHookEx( WH hookType, HookDelegate lpfn, IntPtr hMod, uint dwThreadId);
protected static extern IntPtr SetWindowsHookEx(HookType hookType, HookDelegate hookDelegate, IntPtr moduleHandle, int threadId);
private static extern IntPtr SetWindowsHookEx(int hookCode, HookDelegate hookDelegate, IntPtr moduleHandle, uint threadID);