private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { try { Log.Write("Performing Cleanup, application closing..."); Log.Write(" - Keyboard Hotkey Hooks..."); hook?.Dispose(); Log.Write(" - Done."); Log.Write(" - Combat Routine..."); combatRoutine?.Dispose(); Log.Write(" - Done"); Log.Write(" - WoW Pixel Reading System..."); WoW.Dispose(); Log.Write(" - Done"); Log.Write(" - Mouse Hook"); MouseHook.ForceUnsunscribeFromGlobalMouseEvents(); Log.Write(" - Done"); Log.Write("Cleanup Completed."); e.Cancel = false; } catch (Exception ex) { Log.Write(ex.Message, Color.Red); } }
private void BlockerWindow_Closed(object sender, EventArgs e) { blockerWindow = null; keyTrap?.Dispose(); // Release keyboard trap ResetTimers(settings.LongIntervalTime, settings.ShortIntervalTime); // Set back the taskbarWindow to be the main one Application.Current.MainWindow = this; }
public void EnableKeyboardHook(KeyboardShortcut shortcut) { if (shortcut.Enabled) { _hooks?.Dispose(); _hooks = KeyboardHook.Hook(shortcut, HandleShortcut); } else if (_hooks != null) { _hooks.Dispose(); _hooks = null; } }
private async void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (server != null) { await server.Stop(); } kbHook?.Dispose(); }
public void Dispose() { keyboardHook.RawInputProcessed -= OnRawKeyboardInputProcessed; mouseHook.RawInputProcessed -= OnRawMouseInputProcessed; keyboardHook?.Dispose(); mouseHook?.Dispose(); }
private void UnsetKeyboardHook() { if (_keyboardHook == null) { return; } _keyboardHook.RawInputProcessed -= OnRawKeyboardInputProcessed; _keyboardHook?.Dispose(); }
public static void Register(SettingsService.HotkeyData hotkey) { Trace.WriteLine($"HotkeyService Register {hotkey}"); if (s_hook != null) { s_hook.Dispose(); } s_hook = new KeyboardHook(); s_hook.KeyPressed += Hotkey_KeyPressed; try { s_hook.RegisterHotKey(hotkey.Key, hotkey.Modifiers); } catch (Exception ex) { AppTrace.LogWarning(ex); } }
protected override void OnClosed(EventArgs e) { _brightnessDownHook.Triggered -= _brightnessDownHook_Triggered; _brightnessUpHook.Triggered -= _brightnessUpHook_Triggered; _brightnessUpHook.Dispose(); _brightnessDownHook.Dispose(); BindingOperations.ClearBinding( this, UsesLargeElementsProperty); base.OnClosed(e); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // Dispose the KeyboardHook object to terminate the hook threads _hook.Dispose(); } disposedValue = true; } }
void Form1FormClosing(object sender, FormClosingEventArgs e) { kHook.Dispose(); mHook.Dispose(); if (mouseWriter != null) { mouseWriter.Dispose(); } if (keyboardWriter != null) { keyboardWriter.Dispose(); } }
private void quitToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult d = MessageBox.Show("Are you sure you want to close AmbiLED HD?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (d == DialogResult.Yes) { hook.Dispose();// Unregister hotkey MyNotifyIcon.Visible = false; Environment.Exit(1); serialPort1.Close(); Application.Exit(); } }
protected virtual void Dispose(bool disposing) { Stop(); if (disposing) { mouse.Dispose(); mouseSlim.Dispose(); keyboard.Dispose(); keyboardSlim.Dispose(); keyChar.Dispose(); manualResetEvent.Close(); } }
public override void Stop() { if (!Running) { return; } if (KeyboardHook != null) { KeyboardHook.Dispose(); KeyboardHook = null; } base.Stop(); }
void SetDoubleRevertHotkey(object sender, System.Windows.Input.KeyEventArgs e) { DoubleRevertHotkeyHook.Dispose(); if (e.Key == Key.Escape) { Config.DoubleRevertHotkey = Key.None; currentButton.Content = Config.DoubleRevertHotkey.ToString() ?? "<No Key>"; currentButton = null; KeyDown -= SetDoubleRevertHotkey; return; } Config.DoubleRevertHotkey = e.Key; currentButton.Content = e.Key.ToString(); currentButton = null; KeyDown -= SetDoubleRevertHotkey; DoubleRevertHotkeyHook.Dispose(); DoubleRevertHotkeyHook = new KeyboardHook(); DoubleRevertHotkeyHook.KeyPressed += new EventHandler <KeyPressedEventArgs>(MainWindow.ForceDoubleRevert); DoubleRevertHotkeyHook.RegisterHotKey(HCMHotkeys.ModifierKeys.None, (System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey(e.Key)); return; }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (keyboardHook != null) { keyboardHook.Dispose(); keyboardHook = null; } if (solutionWatcher != null) { solutionWatcher.Dispose(); solutionWatcher = null; } }
private void MainFormFormClosing(object sender, FormClosingEventArgs e) { Settings.Default["Opacity"] = Opacity; Settings.Default.Save(); Settings.Default.Upgrade(); if (mouseHook != null) { mouseHook.Dispose(); mouseHook = null; } if (keyboardHook != null) { keyboardHook.Dispose(); keyboardHook = null; } }
/// <summary> Sets app behaviour on tray icon click and hotkey </summary> private void setWindowVisibilityBehaviour(bool toShowBalloonTip = false) { if (DataManager.Configuration.ToDisplayListOnHotkey) { if (_hook == null) { try { _hook = new KeyboardHook(); // Register the event that is fired after the key press _hook.KeyPressed += hook_KeyPressed; // Register the Ctrl+Alt+S combination as hotkey (Alt Gr = Ctrl+Alt) _hook.RegisterHotKey(ModifierKeys.Control | ModifierKeys.Alt, Keys.S); } catch (InvalidOperationException exception) { MessageBox.Show(exception.Message); LogHelper.SaveError(exception); } } } else { if (_hook != null) { _hook.Dispose(); _hook = null; } } if (toShowBalloonTip) { if (!DataManager.Configuration.ToDisplayListOnTextFocus) { _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; _notifyIcon.BalloonTipTitle = Constants.ProgramName; _notifyIcon.BalloonTipText = @"Word List will appear on tray icon click"; if (DataManager.Configuration.ToDisplayListOnHotkey) { _notifyIcon.BalloonTipText += @" or ""Ctrl+Alt+S"" hotkey"; } _notifyIcon.ShowBalloonTip(3000); } } }
protected virtual void Dispose(bool native) { if (Player.Instance != null) { Player.Instance.Dispose(); } if (_keyboardhook != null) { _keyboardhook.Dispose(); _keyboardhook = null; } if (App.NotifyIcon != null) { App.NotifyIcon.Dispose(); App.NotifyIcon = null; } GC.SuppressFinalize(this); }
protected virtual void Dispose(bool native) { if (_player != null) { _player.Dispose(); _player = null; } if (_keyboardhook != null) { _keyboardhook.Dispose(); _keyboardhook = null; } if (_tray != null) { _tray.Dispose(); _tray = null; } GC.SuppressFinalize(this); }
public void KeyboardHookEnabledDisabledPositive() { int pressedkey = -1; bool fired = false; KeyboardHook hook = new KeyboardHook(); hook.KeyDetected += new KeyHookEventHandler( delegate(OpenNETCF.Win32.WM keyMessage, KeyData keyData) { pressedkey = keyData.KeyCode; fired = true; }); Form f = new Form(); f.ClientSize = new System.Drawing.Size(240, 268); TextBox t = new TextBox(); t.Multiline = true; f.Controls.Add(t); f.Show(); Application2.DoEvents(); t.Focus(); Application2.DoEvents(); SendKeys.Send("a"); Application2.DoEvents(); Assert.IsFalse(fired, "hook fired when disabled"); hook.Enabled = true; SendKeys.Send("h"); Application2.DoEvents(); Assert.IsTrue(fired, "hook did not fire when enabled"); Assert.AreEqual((int)Keys.H, pressedkey); Assert.AreEqual("ah", t.Text); hook.Dispose(); f.Close(); f.Dispose(); }
/// <summary> /// Waits for next key asynchronous. /// </summary> /// <returns>The next key press.</returns> public Task <ushort> WaitForNextKeyAsync() { var taskCompletionSource = new TaskCompletionSource <ushort>(); var hook = new KeyboardHook(ProcessLurker.CurrentProcessId); EventHandler <KeyboardMessageEventArgs> handler = default; handler = (object s, KeyboardMessageEventArgs e) => { taskCompletionSource.SetResult(e.KeyValue); hook.MessageReceived -= handler; hook.Dispose(); }; hook.MessageReceived += handler; hook.InstallAsync().Wait(); return(taskCompletionSource.Task); }
private void emulationCheck_CheckedChanged(object sender, EventArgs e) { emulation = emulationCheck.Checked; if (emulationCheck.Checked) { hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.F); hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.D); hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.S); hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.A); hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.Up); hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.Down); hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.Left); hook.RegisterHotKey(cheapHooker.ModifierKeys.None, Keys.Right); } if (!emulationCheck.Checked) { hook.Dispose(); } }
/// <summary> /// Esta funcion toma los eventos KeyDown sobre los controles y actualiza el texto mostrando la informacion de la HotKey /// </summary> /// <param name="textBox">Control donde se actualiza el texto con la nueva HotKey</param> /// <param name="e">KeyEventArgs e</param> /// <param name="hook">Variable tipo KeyboardHook donde se crea el hook</param> /// <param name="func">Funcion que es llamada cuando las teclas se apretan </param> /// <returns>-1 Si no debe modificarse el valor del setting, 0 si se elimina la hotkey, sino int32 con la KeyData</returns> private int CheckHotKey(TextBox textBox, KeyEventArgs e, ref KeyboardHook hook, EventHandler <KeyPressedEventArgs> func) { e.Handled = true; // Fetch the actual shortcut key. Keys key = e.KeyCode; Keys mods = e.Modifiers; Keys data = e.KeyData; // Ignore modifier keys. if (key == Keys.LShiftKey || key == Keys.RShiftKey || key == Keys.ShiftKey || key == Keys.LControlKey || key == Keys.RControlKey || key == Keys.ControlKey || key == Keys.Alt || key == Keys.LWin || key == Keys.RWin) { return(-1); } // HotKey remover keys if (key == Keys.Back || key == Keys.Delete || key == Keys.Escape) { hook.Dispose(); textBox.Text = "None"; return(0); } // Set the hook hook = new KeyboardHook(); // register the event that is fired after the key press. hook.KeyPressed += func; try { hook.RegisterHotKey(HotKeys.ToModKeys(mods), key); }catch (Exception ex) { MessageBox.Show(ex.Message); return(-1); } // Update the text box. textBox.Text = GetTextForKeyAndMods(key, mods); return((int)data); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var hook = new KeyboardHook(); try { hook.KeyPressed += (_, __) => { // Activate it if it's already there, otherwise create a new one. if (RunWindow != null) { RunWindow.Activate(); } else { RunWindow = new Run(); RunWindow.ShowDialog(); RunWindow = null; } }; hook.RegisterHotKey(ModifierKeys.Win, GetHotkey(args)); } catch { MessageBox.Show("Unable to register the global hotkey Win+" + GetHotkey(args) + ".\r\n\r\nCheck to " + "make sure that the key combination is not already in use by " + "Windows or another application, and that PSRunner is not " + "already running. Only one instance of PSRunner may run at a time.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } Application.Run(); hook.Dispose(); }
private void WindowRadioButton_Checked(object sender, RoutedEventArgs e) { if (_isMouseEnabled) { DisableMouseHook(); _settings.MouseEnabled = true; } else { _settings.MouseEnabled = false; } if (_keyboardHook != null) { _keyboardHook.Dispose(); _keyboardHook = null; } _isRtssEnabled = false; RTSSHandler.KillRTSS(); EnableControls(true); }
private void Enable_Key_Receive(object sender, RoutedEventArgs e) { if (enabled) // try to disable receive key { enabled = false; tempDisabled = false; actionButton.Content = "Enable Receive Key"; actionButton.Background = Brushes.Lime; this.aliveSenders.Clear(); globalKeyHook.Dispose(); globalKeyHook = null; debugTextBlock.Text = "Disabled Receive Key"; } else // try to enable receive key { enabled = true; tempDisabled = false; actionButton.Content = "Disable Receive Key"; actionButton.Background = Brushes.Red; foreach (ProcessInfo info in manager.ManagedProcessList) { if (info.flag == ProcessInfo.ProcessFlag.RECEIVE_KEY) { this.aliveSenders.Add(info.sender); } } globalKeyHook = new KeyboardHook(true); globalKeyHook.KeyDown += Kh_KeyDown; globalKeyHook.KeyUp += Kh_KeyUp; debugTextBlock.Text = "Enable Receive Key"; } }
public override void Dispose() { base.Dispose(); #if DEBUG if (Program.AsyncOperation != null) Program.AsyncOperation.Post(state => #endif #if !DEBUG Program.AppContext.AsyncOperation.Post(state => #endif { if (_keyboardHook != null) { _keyboardHook.Dispose(); _keyboardHook = null; } if (_activeWindowHook != null) { _activeWindowHook.Dispose(); _activeWindowHook = null; } }, null); }
public void Dispose() { KeyboardHook?.Dispose(); MouseHook?.Dispose(); }
public MainWindow() { InitializeComponent(); backlightPercentButtons.Add(new Button() { Content = "25 %", Style = FindResource("ButtonStyle") as Style }); backlightPercentButtons.Add(new Button() { Content = "50 %", Style = FindResource("ButtonSelectedStyle") as Style }); backlightPercentButtons.Add(new Button() { Content = "75 %", Style = FindResource("ButtonStyle") as Style }); backlightPercentButtons.Add(new Button() { Content = "100 %", Style = FindResource("ButtonStyle") as Style }); foreach (var backlightPercentButton in backlightPercentButtons) { backlightPercentButton.Click += BacklightPercentButton_Click; } SourceInitialized += (s, e) => { #if !UI_DESIGN PowerSetting.Init(new WindowInteropHelper(this).Handle); PowerSetting.OnMonitorStateChanged += PowerSetting_OnMonitorStateChanged; KeyboardHook.Init(); KeyboardHook.OnNumLockPressed += KeyboardHook_OnNumLockPressed; #endif }; Loaded += (s, e) => { Hide(); }; Unloaded += (s, e) => { #if !UI_DESIGN PowerSetting.Dispose(); KeyboardHook.Dispose(); #endif }; Closed += (s, e) => { taskbarIcon.Dispose(); #if !UI_DESIGN Chroma.Instance.Unregister(); Chroma.Instance.Uninitialize(); LogitechGSDK.LogiLedShutdown(); #endif }; CreateTaskbarIconInit(); #if !UI_DESIGN WaitForLEDSDKInit(); #else CreateTaskbarIcon(); #endif }
private void Form1_Closing(object sender, CancelEventArgs e) { hook?.Dispose(); }