diff --git a/DisplayMagician/ShortcutItem.cs b/DisplayMagician/ShortcutItem.cs index d8aa9c1..e635bb1 100644 --- a/DisplayMagician/ShortcutItem.cs +++ b/DisplayMagician/ShortcutItem.cs @@ -15,6 +15,7 @@ using System.Text.RegularExpressions; using IWshRuntimeLibrary; using AudioSwitcher.AudioApi.CoreAudio; using AudioSwitcher.AudioApi; +using WK.Libraries.HotkeyListenerNS; namespace DisplayMagician { @@ -110,6 +111,7 @@ namespace DisplayMagician private ShortcutPermanence _displayPermanence = ShortcutPermanence.Temporary; private ShortcutPermanence _audioPermanence = ShortcutPermanence.Temporary; private ShortcutPermanence _capturePermanence = ShortcutPermanence.Temporary; + private Hotkey _hotkey = null; private bool _autoName = true; private ShortcutValidity _isValid; private List _shortcutErrors = new List(); @@ -964,6 +966,19 @@ namespace DisplayMagician } } + public Hotkey Hotkey + { + get + { + return _hotkey; + } + set + { + if (value is Hotkey) + _hotkey = value; + } + } + public int StartTimeout { get diff --git a/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs b/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs index a146845..a43bae7 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs @@ -352,7 +352,7 @@ namespace DisplayMagician.UIForms this.lbl_hotkey_assigned.BackColor = System.Drawing.Color.Transparent; this.lbl_hotkey_assigned.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl_hotkey_assigned.ForeColor = System.Drawing.Color.White; - this.lbl_hotkey_assigned.Location = new System.Drawing.Point(20, 785); + this.lbl_hotkey_assigned.Location = new System.Drawing.Point(20, 782); this.lbl_hotkey_assigned.Name = "lbl_hotkey_assigned"; this.lbl_hotkey_assigned.Size = new System.Drawing.Size(57, 16); this.lbl_hotkey_assigned.TabIndex = 36; diff --git a/DisplayMagician/UIForms/DisplayProfileForm.cs b/DisplayMagician/UIForms/DisplayProfileForm.cs index 618718e..5d200cc 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.cs @@ -294,6 +294,9 @@ namespace DisplayMagician.UIForms lbl_save_profile.Visible = true; } + // Update the Hotkey Label text + UpdateHotkeyLabel(_selectedProfile.Hotkey); + // Refresh the image list view //RefreshImageListView(profile); @@ -301,6 +304,7 @@ namespace DisplayMagician.UIForms dv_profile.Profile = profile; dv_profile.Refresh(); + } private void btn_save_as_Click(object sender, EventArgs e) @@ -462,7 +466,11 @@ namespace DisplayMagician.UIForms private void btn_hotkey_Click(object sender, EventArgs e) { - Hotkey testHotkey = new Hotkey(); + Hotkey testHotkey = null; + if (_selectedProfile.Hotkey is Hotkey) + testHotkey = _selectedProfile.Hotkey; + else + testHotkey = new Hotkey(); string hotkeyHeading = $"Choose a '{_selectedProfile.Name}' Display Profile Hotkey"; string hotkeyDescription = $"Choose a Hotkey (a keyboard shortcut) so that you can apply to this" + Environment.NewLine + "screen using your keyboard. This must be a Hotkey that" + Environment.NewLine + @@ -473,9 +481,12 @@ namespace DisplayMagician.UIForms displayHotkeyForm.ShowDialog(this); if (displayHotkeyForm.DialogResult == DialogResult.OK) { - MessageBox.Show($"We got the hotkey {displayHotkeyForm.Hotkey}", "results", MessageBoxButtons.OK, MessageBoxIcon.Error); - // As this is an edit, we need to manually force saving the shortcut library - //ShortcutRepository.SaveShortcuts(); + // now we save the Hotkey + _selectedProfile.Hotkey = displayHotkeyForm.Hotkey; + // And cause this has changed within a Profile we need to save all the profiles + ProfileRepository.SaveProfiles(); + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + UpdateHotkeyLabel(_selectedProfile.Hotkey); } } private void lbl_hotkey_assigned_Click(object sender, EventArgs e) @@ -483,5 +494,21 @@ namespace DisplayMagician.UIForms btn_hotkey.PerformClick(); } + private void UpdateHotkeyLabel (Hotkey myHotkey) + { + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + if (myHotkey is Hotkey && !(myHotkey.KeyCode == Keys.None && myHotkey.Modifiers == Keys.None)) + { + lbl_hotkey_assigned.Text = "Hotkey: " + HotkeyListener.Convert(myHotkey); + lbl_hotkey_assigned.Visible = true; + } + else + { + lbl_hotkey_assigned.Text = "Hotkey: None"; + lbl_hotkey_assigned.Visible = false; + } + + } + } } \ No newline at end of file diff --git a/DisplayMagician/UIForms/HotkeyForm.cs b/DisplayMagician/UIForms/HotkeyForm.cs index 6e57953..e1ec0b7 100644 --- a/DisplayMagician/UIForms/HotkeyForm.cs +++ b/DisplayMagician/UIForms/HotkeyForm.cs @@ -86,21 +86,33 @@ namespace DisplayMagician.UIForms { this.DialogResult = DialogResult.None; hks.Clear(txt_hotkey); + myHotkey.KeyCode = Keys.None; + myHotkey.Modifiers = Keys.None; this.ActiveControl = txt_hotkey; } private void btn_save_Click(object sender, EventArgs e) - { - Program.HotkeyListener.Update - ( - // Reference the current clipping hotkey for directly updating - // the hotkey without a need for restarting your application. - ref myHotkey, + { - // Convert the selected hotkey's text representation - // to a Hotkey object and update it. - HotkeyListener.Convert(txt_hotkey.Text) - ); + if (!String.IsNullOrWhiteSpace(txt_hotkey.Text)) + { + Program.HotkeyListener.Update + ( + // Reference the current clipping hotkey for directly updating + // the hotkey without a need for restarting your application. + ref myHotkey, + + // Convert the selected hotkey's text representation + // to a Hotkey object and update it. + HotkeyListener.Convert(txt_hotkey.Text) + ); + } + else + { + myHotkey.KeyCode = Keys.None; + myHotkey.Modifiers = Keys.None; + } + this.Hotkey = myHotkey; this.DialogResult = DialogResult.OK; this.Close(); diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 3b5bb8a..385f45b 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -1432,7 +1432,8 @@ namespace DisplayMagician.UIForms // Restart updating the saved_profiles listview ilv_saved_profiles.ResumeLayout(); } - + + UpdateHotkeyLabel(_shortcutToEdit.Hotkey); EnableSaveButtonIfValid(); } @@ -2229,7 +2230,11 @@ namespace DisplayMagician.UIForms private void btn_hotkey_Click(object sender, EventArgs e) { - Hotkey testHotkey = new Hotkey(); + Hotkey testHotkey = null; + if (_shortcutToEdit.Hotkey is Hotkey) + testHotkey = _shortcutToEdit.Hotkey; + else + testHotkey = new Hotkey(); string hotkeyHeading = $"Choose a '{_shortcutToEdit.Name}' Shortcut Hotkey"; string hotkeyDescription = $"Choose a Hotkey (a keyboard shortcut) so that you can start this" + Environment.NewLine + "game shortcut using your keyboard. This must be a Hotkey that" + Environment.NewLine + @@ -2240,9 +2245,10 @@ namespace DisplayMagician.UIForms displayHotkeyForm.ShowDialog(this); if (displayHotkeyForm.DialogResult == DialogResult.OK) { - MessageBox.Show($"We got the hotkey {displayHotkeyForm.Hotkey}", "results", MessageBoxButtons.OK, MessageBoxIcon.Error); - // As this is an edit, we need to manually force saving the shortcut library - //ShortcutRepository.SaveShortcuts(); + // now we save the Hotkey + _shortcutToEdit.Hotkey = displayHotkeyForm.Hotkey; + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + UpdateHotkeyLabel(_shortcutToEdit.Hotkey); } } @@ -2250,5 +2256,21 @@ namespace DisplayMagician.UIForms { btn_hotkey.PerformClick(); } + + private void UpdateHotkeyLabel(Hotkey myHotkey) + { + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + if (myHotkey is Hotkey && !(myHotkey.KeyCode == Keys.None && myHotkey.Modifiers == Keys.None)) + { + lbl_hotkey_assigned.Text = "Hotkey: " + HotkeyListener.Convert(myHotkey); + lbl_hotkey_assigned.Visible = true; + } + else + { + lbl_hotkey_assigned.Text = "Hotkey: None"; + lbl_hotkey_assigned.Visible = false; + } + + } } } \ No newline at end of file diff --git a/DisplayMagicianShared/DisplayMagicianShared.csproj b/DisplayMagicianShared/DisplayMagicianShared.csproj index 3c0be2a..b804433 100644 --- a/DisplayMagicianShared/DisplayMagicianShared.csproj +++ b/DisplayMagicianShared/DisplayMagicianShared.csproj @@ -104,6 +104,9 @@ 1.2.0.1 + + 1.9.0 + 1.0.2.1-beta diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index bea2f81..8f2ee6f 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -9,6 +9,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.Text.RegularExpressions; using IWshRuntimeLibrary; +using WK.Libraries.HotkeyListenerNS; namespace DisplayMagicianShared { @@ -24,6 +25,7 @@ namespace DisplayMagicianShared private string _uuid = ""; private bool _isPossible = false; + private Hotkey _hotkey = null; #region JsonConverterBitmap @@ -150,6 +152,18 @@ namespace DisplayMagicianShared } } + public Hotkey Hotkey { + get + { + return _hotkey; + } + set + { + if (value is Hotkey) + _hotkey = value; + } + } + public string Name { get; set; } public Topology.Path[] Paths { get; set; } = new Topology.Path[0];