private void OnSuccessfullUnhook() { this.keyboardProcessor = null; this.handle = IntPtr.Zero; this.keyData = Keys.None; this.OnStateChanged(new StateChangedEventArgs(this.State)); }
public void InstallHook(Form window) { if (this.State == HookState.Uninstalled) { this.keyboardProcessor = new KeyboardMessageEventHandler(KeyboardProc); this.handle = NativeExports.SetWindowsHookEx(NativeConstants.WH_KEYBOARD_LL, this.keyboardProcessor, IntPtr.Zero, 0); if (this.handle == IntPtr.Zero) { this.keyboardProcessor = null; var errorCode = NativeExports.GetLastError(); throw new Exception(ErrorCodeHelper.GetMessage(errorCode)); } else { this.OnStateChanged(new StateChangedEventArgs(this.State)); } } }