public LockedGlobalHotkey(IGlobalHotkey globalHotkey) { this.Enabled = globalHotkey?.Enabled ?? false; this.KeyCode = globalHotkey?.KeyCode ?? Keys.None; this.Ctrl = globalHotkey?.Ctrl ?? false; this.Alt = globalHotkey?.Alt ?? false; this.Shift = globalHotkey?.Shift ?? false; this.WindowsKey = globalHotkey?.WindowsKey ?? false; }
/// <inheritdoc /> protected override void DisposeInternal() { if (this.globalHotkey != null) { this.globalHotkey.HotkeyPressed -= this.GlobalHotkey_HotkeyPressed; this.globalHotkey.Enabled = false; this.globalHotkey = null; this._active = false; } }
/// <inheritdoc /> protected override void InitInternal() { // InitInternal is executed only if (this.Enabled && this.Active && this.IsValid()) if (this.globalHotkey != null) { this.globalHotkey.HotkeyPressed -= this.GlobalHotkey_HotkeyPressed; } if (this.globalHotkey == null) { this.globalHotkey = new GlobalHotkey(); } // Make sure that we don't try to re-register the key midway updating the combination. if (this.globalHotkey.Enabled) { this.globalHotkey.Enabled = false; } // ReSharper disable once PossibleInvalidOperationException this.globalHotkey.KeyCode = this.Key.Value.ConvertToWindowsFormsKeys(); this.globalHotkey.Alt = this.Modifiers.HasFlag(ModifierKeys.Alt); this.globalHotkey.Ctrl = this.Modifiers.HasFlag(ModifierKeys.Control); this.globalHotkey.Shift = this.Modifiers.HasFlag(ModifierKeys.Shift); this.globalHotkey.WindowsKey = this.Modifiers.HasFlag(ModifierKeys.Windows); this.globalHotkey.HotkeyPressed += this.GlobalHotkey_HotkeyPressed; try { this.globalHotkey.Enabled = true; } catch (HotkeyAlreadyInUseException) { this.isValid = false; this.InvalidReason = "Hotkey is already in use by a different program"; } }
public KeyboardHotkey([NotNull] IGlobalHotkey globalHotkey) { this.globalHotkey = globalHotkey ?? throw new ArgumentNullException(nameof(globalHotkey)); }