IntPtr INativeKeyboard.SetWindowsHookEx(INativeKeyboard.HookType hookType, INativeKeyboard.LowLevelKeyboardProc lpFn, IntPtr hMod, uint dwThreadId) { return(SetWindowsHookEx(hookType, lpFn, hMod, dwThreadId)); }
/// <summary> /// Sets a low-level keyboard hook. /// </summary> /// <param name="callback">The callback of the hook.</param> /// <param name="handle">The handle of the hook. Valid if the method returns <see langword="true" /></param> /// <returns><see langword="true" /> if the hook could successfully be set, <see langword="false" /> otherwise.</returns> public bool TrySetKeyboardHook(INativeKeyboard.LowLevelKeyboardProc callback, out IntPtr handle) { if (!TryGetCurrentModuleHandle(out var moduleHandle)) { handle = IntPtr.Zero; return(false); } handle = SetWindowsHookEx(INativeKeyboard.HookType.WH_KEYBOARD_LL, callback, moduleHandle, 0); return(true); }
private static extern IntPtr SetWindowsHookEx(INativeKeyboard.HookType hookType, INativeKeyboard.LowLevelKeyboardProc lpFn, IntPtr hMod, uint dwThreadId);