From 92c0678e797f251bae0f5965ccd9a6fed14b59b4 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Tue, 27 Apr 2021 21:57:27 +1200 Subject: [PATCH] WIP] commit where I'm up to This is a stopgap place to commit while I test out another hotkey lib. --- DisplayMagician/UIForms/DisplayProfileForm.cs | 2 + DisplayMagician/UIForms/HotkeyForm.cs | 3 + DisplayMagician/UIForms/MainForm.cs | 63 +++++++++++++++++-- DisplayMagician/UIForms/ShortcutForm.cs | 2 +- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/DisplayMagician/UIForms/DisplayProfileForm.cs b/DisplayMagician/UIForms/DisplayProfileForm.cs index 5d200cc..73ab095 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.cs @@ -245,6 +245,7 @@ namespace DisplayMagician.UIForms // Refresh the Profile UI RefreshDisplayProfileUI(); + } @@ -478,6 +479,7 @@ namespace DisplayMagician.UIForms "might not see it."; HotkeyForm displayHotkeyForm = new HotkeyForm(testHotkey,hotkeyHeading, hotkeyDescription); //ilv_saved_shortcuts.SuspendLayout(); + //Program.HotkeyListener.SuspendOn(displayHotkeyForm); displayHotkeyForm.ShowDialog(this); if (displayHotkeyForm.DialogResult == DialogResult.OK) { diff --git a/DisplayMagician/UIForms/HotkeyForm.cs b/DisplayMagician/UIForms/HotkeyForm.cs index e1ec0b7..9b8878e 100644 --- a/DisplayMagician/UIForms/HotkeyForm.cs +++ b/DisplayMagician/UIForms/HotkeyForm.cs @@ -13,6 +13,7 @@ namespace DisplayMagician.UIForms { public partial class HotkeyForm : Form { + //HotkeyListener myHotkeyListener = null; HotkeySelector hks; Hotkey myHotkey = null; @@ -51,6 +52,8 @@ namespace DisplayMagician.UIForms { InitializeComponent(); + //myHotkeyListener = hotkeyListener; + if (hotkeyToEdit == null) myHotkey = new Hotkey(); else diff --git a/DisplayMagician/UIForms/MainForm.cs b/DisplayMagician/UIForms/MainForm.cs index 3660553..f4d4173 100644 --- a/DisplayMagician/UIForms/MainForm.cs +++ b/DisplayMagician/UIForms/MainForm.cs @@ -11,6 +11,7 @@ using System.Net; using Windows.Data.Xml.Dom; using Microsoft.Toolkit.Uwp.Notifications; using WK.Libraries.HotkeyListenerNS; +using System.Collections.Generic; namespace DisplayMagician.UIForms { @@ -19,7 +20,12 @@ namespace DisplayMagician.UIForms private bool allowVisible; // ContextMenu's Show command used private bool allowClose; // ContextMenu's Exit command used + private HotkeyListener hotkeyListener = new HotkeyListener(); private Hotkey hotkeyMainWindow; + private Hotkey hotkeyShortcutLibraryWindow; + private Hotkey hotkeyDisplayProfileWindow; + private Dictionary hotkeyDisplayProfiles = new Dictionary() { }; + private Dictionary hotkeyShortcuts = new Dictionary() { }; private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); @@ -36,11 +42,36 @@ namespace DisplayMagician.UIForms // Define a new hotkey using the Hotkey class. // Parameters are: [modifiers], [keys]. - hotkeyMainWindow = new Hotkey(Keys.Control | Keys.Shift, Keys.W); - Program.HotkeyListener.Add(hotkeyMainWindow); + //hotkeyMainWindow = new Hotkey(Keys.Control | Keys.Shift, Keys.W); + //Program.HotkeyListener.Add(hotkeyMainWindow); + + /*if (Program.AppProgramSettings.MainWindowHotkey) + hotkeyMainWindow = new Hotkey(Program.AppProgramSettings.MainWindowHotkey); + if (Program.AppProgramSettings.ShortcutLibraryWindow) + hotkeyShortcutLibraryWindow = new Hotkey(Program.AppProgramSettings.ShortcutLibraryWindow); + if (Program.AppProgramSettings.DisplayProfileWindow) + hotkeyDisplayProfileWindow = new Hotkey(Program.AppProgramSettings.DisplayProfileWindow);*/ + + // Add all the Profile Hotkeys that are set + foreach (ProfileItem myProfile in ProfileRepository.AllProfiles) + { + if (myProfile.Hotkey is Hotkey && myProfile.Hotkey.Modifiers != Keys.None && myProfile.Hotkey.KeyCode != Keys.None) + { + hotkeyDisplayProfiles.Add(myProfile.Hotkey, myProfile.UUID); + } + } + + // Add all the Shortcut Hotkeys that are set + foreach (ShortcutItem myShortcut in ShortcutRepository.AllShortcuts) + { + if (myShortcut.Hotkey is Hotkey && myShortcut.Hotkey.Modifiers != Keys.None && myShortcut.Hotkey.KeyCode != Keys.None) + { + hotkeyShortcuts.Add(myShortcut.Hotkey, myShortcut.UUID); + } + } + // And now connect up our processing function + Program.HotkeyListener.HotkeyPressed += Hkl_WindowHotkeyPressed; - // Register a HotkeyPressed event. - Program.HotkeyListener.HotkeyPressed += Hkl_MainWindowHotkeyPressed; if (Program.AppProgramSettings.MinimiseOnStart) @@ -103,7 +134,9 @@ namespace DisplayMagician.UIForms shortcutLibraryForm.ShowDialog(this); } - } + + + } protected override void SetVisibleCore(bool value) { @@ -503,10 +536,28 @@ namespace DisplayMagician.UIForms openApplicationWindow(); } - private void Hkl_MainWindowHotkeyPressed(object sender, HotkeyEventArgs e) + private void Hkl_WindowHotkeyPressed(object sender, HotkeyEventArgs e) { if (e.Hotkey == hotkeyMainWindow) openApplicationWindow(); + else if (e.Hotkey == hotkeyDisplayProfileWindow) + btn_setup_display_profiles.PerformClick(); + else if (e.Hotkey == hotkeyDisplayProfileWindow) + btn_setup_game_shortcuts.PerformClick(); + else if (hotkeyDisplayProfiles.ContainsKey(e.Hotkey)) + { + string displayProfileUUID = hotkeyDisplayProfiles[e.Hotkey]; + ProfileItem chosenProfile = ProfileRepository.GetProfile(displayProfileUUID); + if (chosenProfile is ProfileItem) + Program.ApplyProfile(chosenProfile); + } + else if (hotkeyShortcuts.ContainsKey(e.Hotkey)) + { + string shortcutUUID = hotkeyShortcuts[e.Hotkey]; + ShortcutItem chosenShortcut = ShortcutRepository.GetShortcut(shortcutUUID); + if (chosenShortcut is ShortcutItem) + ShortcutRepository.RunShortcut(chosenShortcut); + } } } } diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 385f45b..356bafa 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -2241,7 +2241,7 @@ namespace DisplayMagician.UIForms "is unique across all your applications otherwise DisplayMagician" + Environment.NewLine + "might not see it."; HotkeyForm displayHotkeyForm = new HotkeyForm(testHotkey, hotkeyHeading, hotkeyDescription); - //ilv_saved_shortcuts.SuspendLayout(); + //Program.HotkeyListener.SuspendOn(displayHotkeyForm); displayHotkeyForm.ShowDialog(this); if (displayHotkeyForm.DialogResult == DialogResult.OK) {