public void RegisterHotkey() { if (HotKeyWindow == null) { HotKeyWindow = new HotKeyNativeWindow(this); } try { if (Key != Keys.None) { HotKeyWindow.RegisterHotkey(); } else { if (HotKeyWindow.Handle != IntPtr.Zero) { HotKeyWindow.DestroyHandle(); } HotKeyWindow = null; } } catch { if (HotKeyWindow.Handle != IntPtr.Zero) { HotKeyWindow.DestroyHandle(); } HotKeyWindow = null; throw; } IsRegistered = true; }
/// <summary> /// Register a hotkey combination of one or more Modifers and a Key. /// </summary> /// <remarks> /// This method uses the values of the Modifiers and Key properties. If /// Modifiers == Modifiers.None and Key = Keys.None then any current hotkey combination /// represented by this instance is deactivated. Calling this method a subsequent time with /// a different combination will cause the current combination to be replaced and the new hotkey /// combination installed. If the hotkey registration process fails (for example the hotkey combination /// is already registered) then a Win32Exception is thrown. /// </remarks> public void RegisterHotkey() { if (this.HotKeyWindow == null) { this.HotKeyWindow = new HotKeyNativeWindow(this); } try { if (Modifiers != Modifiers.None && Key != Keys.None) { this.HotKeyWindow.RegisterHotkey(); } else { if (HotKeyWindow.Handle != IntPtr.Zero) { HotKeyWindow.DestroyHandle(); } HotKeyWindow = null; } } catch { if (HotKeyWindow.Handle != IntPtr.Zero) { HotKeyWindow.DestroyHandle(); } this.HotKeyWindow = null; throw; } }
public void Dispose() { // unregister the current hotkey... if (HotKeyWindow != null) { HotKeyWindow.UnregisterHotkey(); } }
public void UnregsiterHotkey() { if (IsRegistered && HotKeyWindow != null) { HotKeyWindow.UnregisterHotkey(); } IsRegistered = false; }
private HotKeyRegister() { hkWindow = new HotKeyWindow(); register = new System.Collections.Hashtable(); hkWindow.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { IHotKeyConsumer ihkc = (IHotKeyConsumer)register[GetKey(args.Modifier, args.Key)]; if (ihkc != null) { ihkc.HotKeyPressed(args); } //Disabling this so that only the consumer will consume the key press. //if (AnyHotKeyPressed != null) // AnyHotKeyPressed(this, args); }; }
public bool RegisterHotkey() { if (HotKeyWindow == null) { HotKeyWindow = new HotKeyNativeWindow(this); } try { if (Key != Keys.None) { HotKeyWindow.RegisterHotkey(); } else { if (HotKeyWindow.Handle != IntPtr.Zero) { HotKeyWindow.DestroyHandle(); } HotKeyWindow = null; } IsRegistered = true; } catch { if (HotKeyWindow.Handle != IntPtr.Zero) { HotKeyWindow.DestroyHandle(); } HotKeyWindow = null; IsRegistered = false; } return(IsRegistered); }
private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e) { try { //Only this window key pressing if (e.Key == Key.F1) { ShowVersionWindow(); return; } if (e.Key == Key.F2) { HotKeyWindow hkw = new HotKeyWindow(); CUtilWin.ShowDialogOnCenter(hkw, this); } if (e.Key == Key.RightCtrl || e.Key == Key.LeftCtrl) { //If in stock zone do close only by instrument end get out. //Else close all instrument - do send data closeall positions //and cancell all orders commands foreach (var controlMarket in KernelTerminal.ViewDispatcher.LstControlMarket) { if (controlMarket.ControlStockInstance.IsInStockArea) { CloseInstrumentPositions(controlMarket); CancellInstrOrder(controlMarket); return; } } //not in ControlStock - do cancell and close all CloseAllPositions(); CancellAllOrders(); return; } if (e.Key == Key.Space) { //All the same as for close (see above) foreach (var controlMarket in KernelTerminal.ViewDispatcher.LstControlMarket) { if (controlMarket.ControlStockInstance.IsInStockArea) { CancellInstrOrder(controlMarket); return; } } CancellAllOrders(); return; } /** Cause on child control events not triggers (unknown reason) do it forcely. * */ foreach (var v in KernelTerminal.ViewDispatcher.LstControlMarket) { v.ControlMarket_PreviewKeyDown(sender, e); } } catch (Exception exc) { Error("MainWindow.MainWindow_PreviewKeyDown", exc); } }