/// <summary> /// General invocation handler /// </summary> /// <param name="hotKeyDelegate"></param> private void InvokeHotKeyHandler(HotKeyHandler hotKeyDelegate) { if (hotKeyDelegate != null) { hotKeyDelegate(this, new HotKeyArgs(DateTime.Now)); } }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode < 0) { return(CallNextHookEx(_hookId, nCode, wParam, lParam)); } var vkCode = Marshal.ReadInt32(lParam); var wmParam = (Wm)wParam; var isDown = wmParam is Wm.Keydown or Wm.SysKeyDown; var isUp = wmParam is Wm.Keyup or Wm.SysKeyUp; if (isDown || isUp) { var hotKey = HotKeyHandler.HasKey(vkCode); if (hotKey != null) { Task.Run(() => HotKeyHandler.TryRunAction(hotKey, wmParam)); return(IntPtr.Parse("1")); } } if (isDown) { KeyDown?.Invoke(vkCode); } return(CallNextHookEx(_hookId, nCode, wParam, lParam)); }
/// <summary> /// Register a hotkey /// </summary> /// <param name="hWnd">The window which will get the event</param> /// <param name="modifierKeyCode">The modifier, e.g.: Modifiers.CTRL, Modifiers.NONE or Modifiers.ALT</param> /// <param name="virtualKeyCode">The virtual key code</param> /// <param name="handler">A HotKeyHandler, this will be called to handle the hotkey press</param> /// <returns>the hotkey number, -1 if failed</returns> public static int RegisterHotKey(string hotkeyString, HotKeyHandler handler) { if (hotkeyHWND == IntPtr.Zero) { LOG.Warn("hotkeyHWND not registered!"); return(-1); } ModifierKeys modifiers = HotkeyModifiersFromString(hotkeyString); Key key = HotkeyFromString(hotkeyString); if (key == Key.None) { LOG.Warn("Trying to register a Keys.none hotkey, ignoring"); return(0); } if (RegisterHotKey(hotkeyHWND, hotKeyCounter, (uint)modifiers, (uint)KeyInterop.VirtualKeyFromKey(key))) { keyHandlers.Add(hotKeyCounter, handler); return(hotKeyCounter++); } else { LOG.Warn(String.Format("Couldn't register hotkey modifier {0} key {1}", modifiers, key)); return(-1); } }
/// <summary> /// General invocation handler /// </summary> /// <param name="hotKeyDelegate"></param> private void InvokeHotKeyHandler(HotKeyHandler hotKeyDelegate) { if (hotKeyDelegate != null) { hotKeyDelegate(this, new EventArgs()); } }
private void InvokeHotKeyHandler(HotKeyHandler hotKeyDelegate) { if (hotKeyDelegate != null) { hotKeyDelegate(this); } }
private void RegisterHandler(string spec, HotKeyHandler handler) { if (string.IsNullOrEmpty(spec)) { return; //this can happen and is allowed => simply don't register } if (handler == null) { throw new ArgumentNullException(); } int modifiers = 0, keyCode = 0; try { HotKeyMethods.TranslateStringToKeyValues(spec, out modifiers, out keyCode); } catch (ArgumentException) { //TODO: swallowed exception return; } var reg = HotKeyHandlerRegistration.Register(Form, keyCode, modifiers, handler); if (reg != null) { _handlers.Add(reg.RegistrationKey, reg); } }
/// <summary> /// Register a hotkey /// </summary> /// <param name="hWnd">The window which will get the event</param> /// <param name="modifierKeyCode">The modifier, e.g.: Modifiers.CTRL, Modifiers.NONE or Modifiers.ALT</param> /// <param name="virtualKeyCode">The virtual key code</param> /// <param name="handler">A HotKeyHandler, this will be called to handle the hotkey press</param> /// <returns>the hotkey number, -1 if failed</returns> public static int RegisterHotKey(Keys modifierKeyCode, Keys virtualKeyCode, HotKeyHandler handler) { if (virtualKeyCode == Keys.None) { LOG.Warn("Trying to register a Keys.none hotkey, ignoring"); return(0); } // Convert Modifiers to fit HKM_SETHOTKEY uint modifiers = 0; if ((modifierKeyCode & Keys.Alt) > 0) { modifiers |= (uint)Modifiers.ALT; } if ((modifierKeyCode & Keys.Control) > 0) { modifiers |= (uint)Modifiers.CTRL; } if ((modifierKeyCode & Keys.Shift) > 0) { modifiers |= (uint)Modifiers.SHIFT; } if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) { keyHandlers.Add(hotKeyCounter, handler); return(hotKeyCounter++); } else { LOG.Warn(String.Format("Couldn't register hotkey modifier {0} virtualKeyCode {1}", modifierKeyCode, virtualKeyCode)); return(-1); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Set title to product name (from API) Title = Config.Active.ActiveLicense.ProductName; // Set footer to include version versionInfoTxt.Text = $"MultiTable Pro v{Assembly.GetEntryAssembly().GetName().Version}"; // Set DataContext DataContext = Config.Active; // Refresh the profile list & select Active RefreshProfileList(selectActive: true); // Auto minimize if (Config.Active.AutoMinimize) { WindowState = WindowState.Minimized; } // Start watching open tables watchOpenTablesTimer = new Timer(WatchOpenTables, null, 1000, 1000); // Register hotkeys IntPtr hWnd = new WindowInteropHelper(this).Handle; HotKeyHandler.RegisterHotKey(Config.Active.AsideHotKey, hWnd); ComponentDispatcher.ThreadFilterMessage += new ThreadMessageEventHandler(HotKeyHandler.HotkeyPressed); // Listen for license expiration events Config.Active.ActiveLicense.ExpirationEvent += ActiveLicense_ExpirationEvent; }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Logger.Log("Clean shutdown"); Thread.Sleep(100); App.Current.Properties["IsRunning"] = false; Hide(); HotKeyHandler.UnregisterAllHotkeys(); Thread.Sleep(2000); // Give threaded loops a few seconds to finish up }
private static bool RegisterWrapper(StringBuilder failedKeys, HotKeyHandler handler) { bool success = RegisterHotkey( failedKeys, Settings.Default.HotKey, handler); return(success); }
public static void Init(MainWindow window) { actionPlay = new Action <object>((o) => window.playerPlay_MouseDown(window, null)); actionNext = new Action <object>((o) => window.playerNext_MouseDown(window, null)); actionPrev = new Action <object>((o) => window.playerPrev_MouseDown(window, null)); actionVolUp = new Action <object>((o) => window.ChangeVolume(Player.Volume + (float)o)); actionVolDown = new Action <object>((o) => window.ChangeVolume(Player.Volume - (float)o)); handler = new HotKeyHandler(window); Update(); }
private void SetDefaultConfig() { config.SetConfig(ConfigKey.JumpTime, 2000); config.SetConfig(ConfigKey.PauseTime, 1000); config.SetConfig(ConfigKey.Topmost, false); config.SetConfig(ConfigKey.IntelligentPlaying, true); HotKeyHandler playpause = PlayPause; HotKeyHandler jumpbck = JumpBackward; config.AddHotKeyHandler(new HotKey(Forms.Keys.RControlKey, functions[playpause.Method.Name])); config.AddHotKeyHandler(new HotKey(Forms.Keys.LControlKey, functions[jumpbck.Method.Name])); }
private void KeyDownHandler(object sender, Forms.KeyEventArgs e) { var hotkeys = config.HotKeys; Forms.Keys key = e.KeyCode; intelligentPlayingManager.KeyPressed(key); HotKeyHandler handler = config.GetHandler(key); if (handler != null) { handler(); } }
public void Toggle(List <IAction> nodePipe, HotKey hotKey) { var state = HotKeyHandler.GetState(hotKey.Key); RunnerState = !RunnerState; Task.Run(() => { while (RunnerState) { if (state is KeyStates.Hold or KeyStates.Down) { Console.WriteLine("here"); Run(nodePipe); }
private HotKeyHandlerRegistration(IntPtr hwnd, int key, HotKeyHandler handler) { if (hwnd == IntPtr.Zero) { throw new ArgumentException(); } if (handler == null) { throw new ArgumentNullException(); } _hwnd = hwnd; RegistrationKey = key; Handler = handler; }
/// <summary> /// Initialize a hotkey handler and HotKeys /// </summary> private void InitHotKeys() { this.HotkeyHandler = HotKeyHandler.GetHotkeyHandler(new WindowInteropHelper(this).Handle); SetHotKeyForModeSwitch(); SetHotKeyForToggleRecord(); SetHotKeyForTogglePause(); SetHotKeyForActivatingMainWindow(); SetHotKeyForMoveToParent(); SetHotKeyForMoveToFirstChild(); SetHotKeyForMoveToLastChild(); SetHotKeyForMoveToNextSibbling(); SetHotKeyForMoveToPreviousSibbling(); }
/// <summary> /// Sets the hotkey handler, only one can be set /// </summary> /// <param name="hndl"></param> public static void SetHotkeyHandler(HotKeyHandler hndl) { ConsoleBase.hndl = hndl; hotkey = hndl != null; if (hotkey) { if (thd != null) { return; } thd = new Thread(Thd); thd.Start(); } else { NativeClass.NullThread(ref thd); } }
/// <summary> /// Register a hotkey /// </summary> /// <param name="hWnd">The window which will get the event</param> /// <param name="modifierKeyCode">The modifier, e.g.: Modifiers.CTRL, Modifiers.NONE or Modifiers.ALT</param> /// <param name="virtualKeyCode">The virtual key code</param> /// <param name="handler">A HotKeyHandler, this will be called to handle the hotkey press</param> /// <returns>the hotkey number, -1 if failed</returns> public static int RegisterHotKey(Keys modifierKeyCode, Keys virtualKeyCode, HotKeyHandler handler) { if (virtualKeyCode == Keys.None) { LOG.Warn("Trying to register a Keys.none hotkey, ignoring"); return(0); } // Convert Modifiers to fit HKM_SETHOTKEY uint modifiers = 0; if ((modifierKeyCode & Keys.Alt) > 0) { modifiers |= (uint)Modifiers.ALT; } if ((modifierKeyCode & Keys.Control) > 0) { modifiers |= (uint)Modifiers.CTRL; } if ((modifierKeyCode & Keys.Shift) > 0) { modifiers |= (uint)Modifiers.SHIFT; } if (modifierKeyCode == Keys.LWin || modifierKeyCode == Keys.RWin) { modifiers |= (uint)Modifiers.WIN; } // Disable repeating hotkey for Windows 7 and beyond, as described in #1559 if (isWindows7OrOlder) { modifiers |= (uint)Modifiers.NO_REPEAT; } if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) { keyHandlers.Add(hotKeyCounter, handler); return(hotKeyCounter++); } else { LOG.Warn(String.Format("Couldn't register hotkey modifier {0} virtualKeyCode {1}", modifierKeyCode, virtualKeyCode)); return(-1); } }
/// <summary> /// Register a hotkey /// </summary> /// <param name="modifierKeyCode">The modifier, e.g.: Modifiers.CTRL, Modifiers.NONE or Modifiers.ALT</param> /// <param name="virtualKeyCode">The virtual key code</param> /// <param name="handler">A HotKeyHandler, this will be called to handle the hotkey press</param> /// <returns>the hotkey number, -1 if failed</returns> public static int RegisterHotKey(Keys modifierKeyCode, Keys virtualKeyCode, HotKeyHandler handler) { if (virtualKeyCode == Keys.None) { Log.Warn().WriteLine("Trying to register a Keys.none hotkey, ignoring"); return(0); } // Convert Modifiers to fit HKM_SETHOTKEY uint modifiers = 0; if ((modifierKeyCode & Keys.Alt) > 0) { modifiers |= (uint)Modifiers.ALT; } if ((modifierKeyCode & Keys.Control) > 0) { modifiers |= (uint)Modifiers.CTRL; } if ((modifierKeyCode & Keys.Shift) > 0) { modifiers |= (uint)Modifiers.SHIFT; } if (modifierKeyCode == Keys.LWin || modifierKeyCode == Keys.RWin) { modifiers |= (uint)Modifiers.WIN; } // Disable repeating hotkey for Windows 7 and beyond, as described in #1559 if (!WindowsVersion.IsWindows7OrLater) { modifiers |= (uint)Modifiers.NO_REPEAT; } if (RegisterHotKey(_hotkeyHwnd, _hotKeyCounter, modifiers, (uint)virtualKeyCode)) { KeyHandlers.Add(_hotKeyCounter, handler); return(_hotKeyCounter++); } Log.Warn().WriteLine($"Couldn't register hotkey modifier {modifierKeyCode} virtualKeyCode {virtualKeyCode}"); return(-1); }
private static bool RegisterWrapper(StringBuilder failedKeys, HotKeyHandler handler, bool ignoreFailedRegistration) { #warning todo with Properties.Settings.Default.HotKey //IniValue hotkeyValue = _conf.Values[configurationKey]; try { bool success = RegisterHotkey(failedKeys, //hotkeyValue.Value.ToString(), Properties.Settings.Default.HotKey, handler); if (!success && ignoreFailedRegistration) { #warning logging //LOG.DebugFormat("Ignoring failed hotkey registration for {0}, with value '{1}', resetting to 'None'.", functionName, hotkeyValue); #warning todo with Properties.Settings.Default.HotKey //_conf.Values[configurationKey].Value = Keys.None.ToString(); //_conf.IsDirty = true; } return(success); } catch (Exception) { #warning logging //LOG.Warn(ex); //LOG.WarnFormat("Restoring default hotkey for {0}, stored under {1} from '{2}' to '{3}'", functionName, configurationKey, hotkeyValue.Value, hotkeyValue.Attributes.DefaultValue); // when getting an exception the key wasn't found: reset the hotkey value //hotkeyValue.UseValueOrDefault(null); //hotkeyValue.ContainingIniSection.IsDirty = true; #warning todo set default Properties.Settings.Default.HotKey = return(RegisterHotkey(failedKeys, //hotkeyValue.Value.ToString(), Properties.Settings.Default.HotKey, handler)); } }
public ISensor Build() { var parser = new SettingsParser(_parameters, _sockets); var settings = parser.Parse(); var translation = new Translation(); var scheduler = new Scheduler(); var builder = new TrayIconMenuBuilder(translation); foreach (var socket in _sockets) { builder.AddSocketStrip(socket.Key); } builder.AddSeparatorStrip(); builder.AddModeStrip(_modes); builder.AddSeparatorStrip(); builder.AddExitStrip(); var trayIcon = builder.Build(); var hotKeyHandler = new HotKeyHandler(new HotKeyNotifier(), settings.HotKeys); return(new GUI(translation, scheduler, trayIcon, hotKeyHandler)); }
/// <summary> /// Registers a new hotkey and returns a handle to the registration. /// </summary> /// <returns>Returns null on failure.</returns> public static HotKeyHandlerRegistration Register(Form owner, int keyCode, int modifiers, HotKeyHandler handler) { var key = ++_lastUsedKey; if (!HotKeyMethods.RegisterHotKey(owner.Handle, key, modifiers, keyCode)) { Log.Write("Failed to create hotkey on key {0} with modifiers {1}", keyCode, modifiers); return null; } return new HotKeyHandlerRegistration(owner.Handle, key, handler); }
public static int RegisterHotKey(string hotkey, HotKeyHandler handler) { return RegisterHotKey(HotkeyModifiersFromString(hotkey), HotkeyFromString(hotkey),handler); }
/// <summary> /// Register a hotkey /// </summary> /// <param name="hWnd">The window which will get the event</param> /// <param name="modifierKeyCode">The modifier, e.g.: Modifiers.CTRL, Modifiers.NONE or Modifiers.ALT</param> /// <param name="virtualKeyCode">The virtual key code</param> /// <param name="handler">A HotKeyHandler, this will be called to handle the hotkey press</param> /// <returns>the hotkey number, -1 if failed</returns> public static int RegisterHotKey(Keys modifierKeyCode, Keys virtualKeyCode, HotKeyHandler handler) { if (virtualKeyCode == Keys.None) { LOG.Warn("Trying to register a Keys.none hotkey, ignoring"); return 0; } // Convert Modifiers to fit HKM_SETHOTKEY uint modifiers = 0; if ((modifierKeyCode & Keys.Alt) > 0) { modifiers |= (uint)Modifiers.ALT; } if ((modifierKeyCode & Keys.Control) > 0) { modifiers |= (uint)Modifiers.CTRL; } if ((modifierKeyCode & Keys.Shift) > 0) { modifiers |= (uint)Modifiers.SHIFT; } if (modifierKeyCode == Keys.LWin || modifierKeyCode == Keys.RWin) { modifiers |= (uint)Modifiers.WIN; } // Disable repeating hotkey for Windows 7 and beyond, as described in #1559 if (isWindows7OrOlder) { modifiers |= (uint)Modifiers.NO_REPEAT; } if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) { keyHandlers.Add(hotKeyCounter, handler); return hotKeyCounter++; } else { LOG.Warn(String.Format("Couldn't register hotkey modifier {0} virtualKeyCode {1}", modifierKeyCode, virtualKeyCode)); return -1; } }
/// <summary> /// Helper method to cleanly register a hotkey. /// </summary> /// <param name="failedKeys">failedKeys.</param> /// <param name="hotkeyString">hotkeyString.</param> /// <param name="handler">handler.</param> /// <returns>bool success.</returns> private static bool RegisterHotkey(StringBuilder failedKeys, string hotkeyString, HotKeyHandler handler) { Keys modifierKeyCode = HotkeyModifiersFromString(hotkeyString); Keys virtualKeyCode = HotkeyFromString(hotkeyString); if (!Keys.None.Equals(virtualKeyCode)) { if (RegisterHotKey(modifierKeyCode, virtualKeyCode, handler) < 0) { if (failedKeys.Length > 0) { failedKeys.Append(", "); } failedKeys.Append(hotkeyString); return(false); } } return(true); }
private bool RegisterWrapper(StringBuilder failedKeys, string functionName, string configurationKey, HotKeyHandler handler, bool ignoreFailedRegistration) { var hotkeyValue = _coreConfiguration[configurationKey]; try { var success = RegisterHotkey(failedKeys, functionName, hotkeyValue.Value.ToString(), handler); if (!success && ignoreFailedRegistration) { Log.Debug().WriteLine("Ignoring failed hotkey registration for {0}, with value '{1}', resetting to 'None'.", functionName, hotkeyValue); _coreConfiguration[configurationKey].Value = Keys.None.ToString(); } return(success); } catch (Exception ex) { Log.Warn().WriteLine(ex); Log.Warn().WriteLine("Restoring default hotkey for {0}, stored under {1} from '{2}' to '{3}'", functionName, configurationKey, hotkeyValue.Value, hotkeyValue.DefaultValue); // when getting an exception the key wasn't found: reset the hotkey value hotkeyValue.ResetToDefault(); return(RegisterHotkey(failedKeys, functionName, hotkeyValue.Value.ToString(), handler)); } }
/// <summary> /// Helper method to cleanly register a hotkey /// </summary> /// <param name="failedKeys"></param> /// <param name="functionName"></param> /// <param name="hotkeyString"></param> /// <param name="handler"></param> /// <returns></returns> private static bool RegisterHotkey(StringBuilder failedKeys, string functionName, string hotkeyString, HotKeyHandler handler) { var modifierKeyCode = HotkeyControl.HotkeyModifiersFromString(hotkeyString); var virtualKeyCode = HotkeyControl.HotkeyFromString(hotkeyString); if (!Keys.None.Equals(virtualKeyCode)) { if (HotkeyControl.RegisterHotKey(modifierKeyCode, virtualKeyCode, handler) < 0) { Log.Debug().WriteLine("Failed to register {0} to hotkey: {1}", functionName, hotkeyString); if (failedKeys.Length > 0) { failedKeys.Append(", "); } failedKeys.Append(hotkeyString); return(false); } Log.Debug().WriteLine("Registered {0} to hotkey: {1}", functionName, hotkeyString); } else { Log.Info().WriteLine("Skipping hotkey registration for {0}, no hotkey set!", functionName); } return(true); }
public static int RegisterHotKey(string hotkey, HotKeyHandler handler) { return(RegisterHotKey(HotkeyModifiersFromString(hotkey), HotkeyFromString(hotkey), handler)); }
/// <summary> /// General invocation handler /// </summary> /// <param name="hotKeyDelegate"></param> private void InvokeHotKeyHandler( HotKeyHandler hotKeyDelegate ) { if ( hotKeyDelegate != null ) hotKeyDelegate( this, new HotKeyArgs( DateTime.Now ) ); }
private void InvokeHotKeyHandler( HotKeyHandler hotKeyDelegate ) { if ( hotKeyDelegate != null ) hotKeyDelegate( this ); }
/// <summary> /// Registers a new hotkey and returns a handle to the registration. /// </summary> /// <returns>Returns null on failure.</returns> public static HotKeyHandlerRegistration Register(Form owner, int keyCode, int modifiers, HotKeyHandler handler) { var key = ++_lastUsedKey; if (!HotKeyMethods.RegisterHotKey(owner.Handle, key, modifiers, keyCode)) { Log.Write("Failed to create hotkey on key {0} with modifiers {1}", keyCode, modifiers); return(null); } return(new HotKeyHandlerRegistration(owner.Handle, key, handler)); }
/// <summary> /// Registers a new hotkey and returns a handle to the registration. /// </summary> /// <returns>Returns null on failure.</returns> public static HotKeyHandlerRegistration Register(Form owner, int keyCode, int modifiers, HotKeyHandler handler) { var key = ++_lastUsedKey; if (!HotKeyMethods.RegisterHotKey(owner.Handle, key, modifiers, keyCode)) { Console.Error.WriteLine("Failed to create hotkey on keys {0}.", keyCode); return null; } return new HotKeyHandlerRegistration(owner.Handle, key, handler); }
private HotKeyHandlerRegistration(IntPtr hwnd, int key, HotKeyHandler handler) { if (hwnd == IntPtr.Zero) throw new ArgumentException(); if (handler == null) throw new ArgumentNullException(); _hwnd = hwnd; RegistrationKey = key; Handler = handler; }
private void RegisterHandler(string spec, HotKeyHandler handler) { if (string.IsNullOrEmpty(spec)) return; //this can happen and is allowed => simply don't register if (handler == null) throw new ArgumentNullException(); int modifiers = 0, keyCode = 0; try { HotKeyMethods.TranslateStringToKeyValues(spec, out modifiers, out keyCode); } catch (ArgumentException) { //TODO: swallowed exception return; } var reg = HotKeyHandlerRegistration.Register(Form, keyCode, modifiers, handler); if(reg != null) _handlers.Add(reg.RegistrationKey, reg); }
private static bool RegisterWrapper(StringBuilder failedKeys, string functionName, string configurationKey, HotKeyHandler handler, bool ignoreFailedRegistration) { IniValue hotkeyValue = _conf.Values[configurationKey]; try { bool success = RegisterHotkey(failedKeys, functionName, hotkeyValue.Value.ToString(), handler); if (!success && ignoreFailedRegistration) { LOG.DebugFormat("Ignoring failed hotkey registration for {0}, with value '{1}', resetting to 'None'.", functionName, hotkeyValue); _conf.Values[configurationKey].Value = Keys.None.ToString(); _conf.IsDirty = true; } return success; } catch (Exception ex) { LOG.Warn(ex); LOG.WarnFormat("Restoring default hotkey for {0}, stored under {1} from '{2}' to '{3}'", functionName, configurationKey, hotkeyValue.Value, hotkeyValue.Attributes.DefaultValue); // when getting an exception the key wasn't found: reset the hotkey value hotkeyValue.UseValueOrDefault(null); hotkeyValue.ContainingIniSection.IsDirty = true; return RegisterHotkey(failedKeys, functionName, hotkeyValue.Value.ToString(), handler); } }
/// <summary> /// Register a hotkey /// </summary> /// <param name="hWnd">The window which will get the event</param> /// <param name="modifierKeyCode">The modifier, e.g.: Modifiers.CTRL, Modifiers.NONE or Modifiers.ALT</param> /// <param name="virtualKeyCode">The virtual key code</param> /// <param name="handler">A HotKeyHandler, this will be called to handle the hotkey press</param> /// <returns>the hotkey number, -1 if failed</returns> public static int RegisterHotKey(Keys modifierKeyCode, Keys virtualKeyCode, HotKeyHandler handler) { if (virtualKeyCode == Keys.None) { LOG.Warn("Trying to register a Keys.none hotkey, ignoring"); return 0; } // Convert Modifiers to fit HKM_SETHOTKEY uint modifiers = 0; if ((modifierKeyCode & Keys.Alt) > 0) { modifiers |= (uint)Modifiers.ALT; } if ((modifierKeyCode & Keys.Control) > 0) { modifiers |= (uint)Modifiers.CTRL; } if ((modifierKeyCode & Keys.Shift) > 0) { modifiers |= (uint)Modifiers.SHIFT; } if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) { keyHandlers.Add(hotKeyCounter, handler); return hotKeyCounter++; } else { LOG.Warn(String.Format("Couldn't register hotkey modifier {0} virtualKeyCode {1}", modifierKeyCode, virtualKeyCode)); return -1; } }
public override int?Run(AugmentrexContext context, string[] args) { var opts = Parse <KeyOptions>(context, args); if (opts == null) { return(null); } if (!opts.Add && !opts.Delete) { foreach (var kvp in _bindings) { context.InfoLine("{0} = {1}", kvp.Key, kvp.Value); } return(null); } var info = new HotKeyInfo(opts.Key, opts.Alt, opts.Control, opts.Shift); if (_handler == null) { void KeyHandler(HotKeyInfo info) { var freq = context.Configuration.HotKeyBeepFrequency; if (freq != 0) { context.Ipc.Channel.Beep(freq, context.Configuration.HotKeyBeepDuration); } if (_bindings.TryGetValue(info, out var command)) { context.Interpreter.RunCommand(command, true); } } _handler = new HotKeyHandler(KeyHandler); } if (opts.Add) { var command = string.Join(" ", opts.Fragments); if (string.IsNullOrWhiteSpace(command)) { context.ErrorLine("No command given."); return(null); } if (_bindings.TryAdd(info, command)) { context.HotKeys.Add(info, _handler); context.InfoLine("Added key binding: {0} = {1}", info, command); } else { context.ErrorLine("Key binding already exists: {0} = {1}", info, _bindings[info]); } } if (opts.Delete) { if (_bindings.Remove(info, out var command)) { context.InfoLine("Deleted key binding: {0} = {1}", info, command); } else { context.ErrorLine("Key binding not found: {0}", info); } } return(null); }
/// <summary> /// Helper method to cleanly register a hotkey /// </summary> /// <param name="failedKeys"></param> /// <param name="functionName"></param> /// <param name="hotkeyString"></param> /// <param name="handler"></param> /// <returns></returns> private static bool RegisterHotkey(StringBuilder failedKeys, string hotkeyString, HotKeyHandler handler) { Keys modifierKeyCode = HotkeyControl.HotkeyModifiersFromString(hotkeyString); Keys virtualKeyCode = HotkeyControl.HotkeyFromString(hotkeyString); if (!Keys.None.Equals(virtualKeyCode)) { if (HotkeyControl.RegisterHotKey(modifierKeyCode, virtualKeyCode, handler) < 0) { #warning logging //LOG.DebugFormat("Failed to register {0} to hotkey: {1}", functionName, hotkeyString); if (failedKeys.Length > 0) { failedKeys.Append(", "); } failedKeys.Append(hotkeyString); return(false); } #warning logging //LOG.DebugFormat("Registered {0} to hotkey: {1}", functionName, hotkeyString); } else { #warning logging //LOG.InfoFormat("Skipping hotkey registration for {0}, no hotkey set!", functionName); } return(true); }
/// <summary> /// Helper method to cleanly register a hotkey /// </summary> /// <param name="failedKeys"></param> /// <param name="functionName"></param> /// <param name="hotkeyString"></param> /// <param name="handler"></param> /// <returns></returns> private static bool RegisterHotkey(StringBuilder failedKeys, string functionName, string hotkeyString, HotKeyHandler handler) { Keys modifierKeyCode = HotkeyControl.HotkeyModifiersFromString(hotkeyString); Keys virtualKeyCode = HotkeyControl.HotkeyFromString(hotkeyString); if (!Keys.None.Equals(virtualKeyCode)) { if (HotkeyControl.RegisterHotKey(modifierKeyCode, virtualKeyCode, handler) < 0) { LOG.DebugFormat("Failed to register {0} to hotkey: {1}", functionName, hotkeyString); if (failedKeys.Length > 0) { failedKeys.Append(", "); } failedKeys.Append(hotkeyString); return false; } LOG.DebugFormat("Registered {0} to hotkey: {1}", functionName, hotkeyString); } else { LOG.InfoFormat("Skipping hotkey registration for {0}, no hotkey set!", functionName); } return true; }
public Function(HotKeyHandler Handler, string FunctionText) { this.KeyHandler = Handler; this.FunctionText = FunctionText; }