/// <inheritdoc /> public override void UnregisterHotKey(VirtualKeys key, Modifiers modifiers) { // remove no repeat before adding to list to avoid getting different hash modifiers = (Modifiers)((uint)modifiers & 0xF); KeyModifierCombination combination = new KeyModifierCombination(key, modifiers); if (!HotKeys.ContainsKey(combination)) { String error = $"Failed to unregister hotKey : HotKey \"{key}+{modifiers}\" is not registered"; Logger.Warn(error); throw new HotKeyException(error); } try { HotKey tmpHotKey = HotKeys[combination]; tmpHotKey.UnregisterHotKey(); HotKeysId.Remove(tmpHotKey.Id); HotKeys.Remove(combination); } catch (HotKeyException e) { Logger.Warn("Failed to unregister hotKey : {0}", e.Message); throw; } }
/// <inheritdoc /> public override void RegisterNewHotkey(VirtualKeys key, Modifiers modifiers, EventHandler <HotKeyPressedEventArgs> handler) { int id = GetGenerateId(); try { HotKey hotkey = HotKey.RegisterHotKey(IntPtr.Zero, key, modifiers, id); hotkey.HotKeyPressedEvent += handler; // remove no repeat before adding to list to avoid getting different hash modifiers = (Modifiers)((uint)modifiers & 0xF); HotKeys.Add(new KeyModifierCombination(key, modifiers), hotkey); HotKeysId.Add(id); } catch (HotKeyException e) { Logger.Warn("Failed to register hotKey : {0}", e.Message); throw; } }