/// <summary> /// Initializes a new instance of the <see cref="Hotkey"/> class. /// </summary> /// <param name="hotkey"> /// The hotkey in string format. /// </param> public Hotkey(string hotkey) { var hotkeyObj = HotkeyListener.Convert(hotkey); KeyCode = hotkeyObj.KeyCode; Modifiers = hotkeyObj.Modifiers; }
/// <summary> /// Overrides the default window message processing /// to detect the registered Hotkeys when pressed. /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { HotkeyPressed?.Invoke( new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection()), new HotkeyEventArgs { Hotkey = HotkeyListener.Convert(this.Hotkeys[m.WParam.ToInt32()]), SourceApplication = new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection()) }); } else { base.WndProc(ref m); } }
/// <summary> /// Returns a string conversion containing the Hotkey's /// <see cref="KeyCode"/> and <see cref="Modifiers"/> keys. /// </summary> /// <returns><see cref="String"/></returns> public override string ToString() { if (Modifiers == Keys.None) { return(KeyCode.ToString()); } else { return(HotkeyListener.Convert(this)); } }
private void btnSaveClose_Click(object sender, EventArgs e) { // Update the default clipping hotkey // to the new user-defined hotkey. MainForm.hotkeyListener.Update ( // Reference the current clipping hotkey for directly updating // the hotkey without a need for restarting your application. ref MainForm.clippingHotkey, // Convert the selected hotkey's text representation // to a Hotkey object and update it. HotkeyListener.Convert(txtClippingHotkey.Text) ); Close(); }