/// <summary> /// Creates a two input hooks: mouse and keyboard. Requires running Message Loop on the calling thread. /// </summary> public HardwareHook() { _proc = HookCallback; _keyboardHookId = WinAPI.SetKeyboardHook(_proc); _mouseHookId = WinAPI.SetMouseHook(_proc); }
public void Initialize() { _callbacks = new List <OnKeyActionDelegate>(); _proc = HookCallback; _hookID = SetHookKeyboard(_proc); _mouseHookId = SetHookMouse(_proc); // Make sure the hooks succeeded while (_hookID == IntPtr.Zero) { MessageBoxResult dr = MessageBox.Show("Warning, failed to hook keyboard. Should I try again?", "Error", MessageBoxButton.YesNo); if (dr != MessageBoxResult.Yes) { break; } _hookID = SetHookKeyboard(_proc); } while (_mouseHookId == IntPtr.Zero) { MessageBoxResult dr = MessageBox.Show("Warning, failed to hook mouse. Should I try again?", "Error", MessageBoxButton.YesNo); if (dr != MessageBoxResult.Yes) { break; } _mouseHookId = SetHookMouse(_proc); } }
private IntPtr SetKeyboardHook(LowLevelProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return(SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0)); } }
private IntPtr SetHookMouse(LowLevelProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return(SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0)); } }
/// <summary> /// Uses SetWindowsHookEx to set a mouse hook with the given /// LowLevelProc callback method. /// </summary> /// <param name="proc">The callback method to be called.</param> /// <returns>If the function succeeds, the return value is the handle to the hook procedure. /// If the function fails, the return value is NULL.</returns> public static IntPtr SetMouseHook(LowLevelProc proc) { using (var curProcess = Process.GetCurrentProcess()) using (var curModule = curProcess.MainModule) { return(SetWindowsHookEx(WHMOUSELL, proc, GetModuleHandle(curModule.ModuleName), 0)); } }
protected static IntPtr SetHook(LowLevelProc proc, int WH_LL) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } }
private static IntPtr SetHook(int idHook, LowLevelProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return(SetWindowsHookEx(idHook, proc, GetModuleHandle(curModule.ModuleName), 0)); } }
private static IntPtr SetHook(LowLevelProc proc, bool Keyboard) { using (System.Diagnostics.Process curProcess = System.Diagnostics.Process.GetCurrentProcess()) using (System.Diagnostics.ProcessModule curModule = curProcess.MainModule) { return(SetWindowsHookEx(Keyboard ? WH_KEYBOARD_LL : WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0)); } }
public static IntPtr SetMouseHook(LowLevelProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return(SetWindowsHookEx((int)HardwareHookType.WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0)); } }
private void InitializeHooks() { _lowLevelMouseProc = MouseHookCallback; _mouseHookID = SetMouseHook(_lowLevelMouseProc); _lowLevelKeyboardProc = KeyboardHookCallback; _keyboardHookID = SetKeyboardHook(_lowLevelKeyboardProc); }
private IntPtr SetHook(LowLevelProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return(WinApiMethods.SetWindowsHookEx((int)HookType.WH_KEYBOARD_LL, proc, WinApiMethods.GetModuleHandle(curModule.ModuleName), 0)); } }
private static IntPtr SetKeyboardHook(LowLevelProc proc) { using (var curProcess = Process.GetCurrentProcess()) using (var curModule = curProcess.MainModule) { return(SetWindowsHookEx((int)GlobalHookTypes.WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0)); } }
public HookType() { this.HookCallback = DefaultHookCallback; this._proc = new LowLevelProc(this.HookCallback); //Init _hookID = this.SetHook(); }
protected override void DisposeUnmanagedResources() { base.DisposeUnmanagedResources(); WinAPI.UnhookWindowsHookEx(_keyboardHookId); WinAPI.UnhookWindowsHookEx(_mouseHookId); _proc = null; }
public static IntPtr SetWindowsHook(HookType hookType, LowLevelProc callback) { using var currentProcess = Process.GetCurrentProcess(); using var currentModule = currentProcess.MainModule; var handle = Kernel32.GetModuleHandle(currentModule?.ModuleName); var hookId = SetWindowsHookLowLevel(hookType, callback, handle, 0); return(hookId); }
public static bool HookStart() { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { var handle = GetModuleHandle("user32"); _proc = HookCallback; _hookID = SetWindowsHookEx(WH_MOUSE_LL, _proc, handle, 0); return(_hookID != IntPtr.Zero); } }
public static IntPtr SetWindowsHook(int hookType, LowLevelProc callback) { IntPtr hookId; using (var currentProcess = Process.GetCurrentProcess()) using (var currentModule = currentProcess.MainModule) { var handle = NativeMethods.GetModuleHandle(currentModule.ModuleName); hookId = NativeMethods.SetWindowsHookEx(hookType, callback, handle, 0); } return hookId; }
public static IntPtr SetWindowsHook(HookType hookType, LowLevelProc callback) { IntPtr hookId; using (var currentProcess = System.Diagnostics.Process.GetCurrentProcess()) using (var currentModule = currentProcess.MainModule) { var handle = Kernel32.GetModuleHandle(currentModule.ModuleName); hookId = SetWindowsHookLowLevel(hookType, callback, handle, 0); } return(hookId); }
public static IntPtr SetWindowsHook(int hookType, LowLevelProc callback) { IntPtr hookId; using (var currentProcess = Process.GetCurrentProcess()) using (var currentModule = currentProcess.MainModule) { var handle = NativeMethods.GetModuleHandle(currentModule.ModuleName); hookId = NativeMethods.SetWindowsHookEx(hookType, callback, handle, 0); } return(hookId); }
private Hook() { _kproc = kHookReception; _mproc = mHookReception; _khookID = setkHook(_kproc); _mhookID = SetmHook(_mproc); onKeyUp = new LinkedList <OnKeyDelegate>(); onKeyDn = new LinkedList <OnKeyDelegate>(); onMouse = new LinkedList <OnMouseDelegate>(); }
public void Init() { m_OverlayWindow = new MyOverlayWindow(); m_ControllerManager = new ControllerManager(); RunConfig(); m_OverlayWindow.onDrawGraphics += Update; m_KeyboardProc = KeyboardHookCallback; m_KeyboardHookID = SetKeyboardHook(m_KeyboardProc); m_OverlayWindow.Run(); }
/// <summary> // Register key capture method. /// </summary> /// <returns>If successful, a Desktop object, otherwise, null.</returns> private static void RegisterKeyboardHookMethod() { // Get Current Module ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule; // Assign callback function each time keyboard process objKeyboardProcess = new LowLevelProc(CaptureKey); // Assign callback function each time mouse process objMouseProcess = new LowLevelProc(CaptureMouseButton); // Setting Hook of Keyboard Process for current module ptrKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, objKeyboardProcess, GetModuleHandle(objCurrentModule.ModuleName), 0); ptrMouseHook = SetWindowsHookEx(WH_MOUSE_LL, objMouseProcess, GetModuleHandle(objCurrentModule.ModuleName), 0); }
public void Initialize() { _callbacks = new List<OnKeyActionDelegate>(); _proc = HookCallback; _hookID = SetHookKeyboard(_proc); _mouseHookId = SetHookMouse(_proc); // Make sure the hooks succeeded while (_hookID == IntPtr.Zero) { MessageBoxResult dr = MessageBox.Show("Warning, failed to hook keyboard. Should I try again?", "Error", MessageBoxButton.YesNo); if (dr != MessageBoxResult.Yes) break; _hookID = SetHookKeyboard(_proc); } while (_mouseHookId == IntPtr.Zero) { MessageBoxResult dr = MessageBox.Show("Warning, failed to hook mouse. Should I try again?", "Error", MessageBoxButton.YesNo); if (dr != MessageBoxResult.Yes) break; _mouseHookId = SetHookMouse(_proc); } }
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hmod, uint dwThread);
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hMod, uint dwThreadId);
/// <summary> /// Uses SetWindowsHookEx to set a mouse hook with the given /// LowLevelProc callback method. /// </summary> /// <param name="proc">The callback method to be called.</param> /// <returns>If the function succeeds, the return value is the handle to the hook procedure. /// If the function fails, the return value is NULL.</returns> public static IntPtr SetMouseHook(LowLevelProc proc) { using (var curProcess = Process.GetCurrentProcess()) using (var curModule = curProcess.MainModule) { return SetWindowsHookEx(WHMOUSELL, proc, GetModuleHandle(curModule.ModuleName), 0); } }
static KeyboardHook() { _proc = HookCallback; }
public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hMod, uint dwThreadId);
private static IntPtr SetHook(LowLevelProc proc) { return(SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0)); }
public LowLevelKeyboardListener() { proc = HookCallback; }
public static extern IntPtr SetWindowsHookLowLevel(HookType code, LowLevelProc func, IntPtr hInstance, int threadId);
private IntPtr SetHookMouse(LowLevelProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } }
private static extern IntPtr SetWindowsHookEx( int hookID, LowLevelProc callback, IntPtr module, uint threadId);
/// <summary> // Register key capture method. /// </summary> /// <returns>If successful, a Desktop object, otherwise, null.</returns> private static void RegisterKeyboardHookMethod() { // Get Current Module ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule; // Assign callback function each time keyboard process objKeyboardProcess = new LowLevelProc(CaptureKey); // Assign callback function each time mouse process objMouseProcess = new LowLevelProc(CaptureMouseButton); // Setting Hook of Keyboard Process for current module ptrKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, objKeyboardProcess, GetModuleHandle(objCurrentModule.ModuleName), 0); ptrMouseHook = SetWindowsHookEx(WH_MOUSE_LL, objMouseProcess, GetModuleHandle(objCurrentModule.ModuleName), 0); }
public KeyboardHook() { callback = KeyboardHookCallback; }
private static IntPtr SetKBHook(LowLevelProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } }
private static extern IntPtr SetWindowsHookEx(int id, LowLevelProc callback, IntPtr hMod, uint dwThreadId);
static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc callback, IntPtr hInstance, uint threadId);
public MouseHook() { callback = MouseHookCallback; }
public Hook(int hook) { _hookProc = new LowLevelProc(HookCallback); _hookID = SetHook(_hookProc, hook); }
static extern IntPtr SetWindowsHookEx(HookType hookType, LowLevelProc lpfn, IntPtr hMod, int dwThreadId);
public GlobalServiceBase(Game game) : base(game) { _Proc = HookCallback; }
private static extern IntPtr SetWindowsHookEx(int id, LowLevelProc callback, IntPtr hMod, uint dwThreadId);
public MouseHook(string identifier) { Identifier = identifier; _callback = MouseHookCallback; }