mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] Still moving to NHotkey
This commit is contained in:
parent
209e3f0338
commit
e9f401960e
@ -15,7 +15,7 @@ using System.Text.RegularExpressions;
|
|||||||
using IWshRuntimeLibrary;
|
using IWshRuntimeLibrary;
|
||||||
using AudioSwitcher.AudioApi.CoreAudio;
|
using AudioSwitcher.AudioApi.CoreAudio;
|
||||||
using AudioSwitcher.AudioApi;
|
using AudioSwitcher.AudioApi;
|
||||||
using WK.Libraries.HotkeyListenerNS;
|
//using WK.Libraries.HotkeyListenerNS;
|
||||||
|
|
||||||
namespace DisplayMagician
|
namespace DisplayMagician
|
||||||
{
|
{
|
||||||
@ -111,7 +111,7 @@ namespace DisplayMagician
|
|||||||
private ShortcutPermanence _displayPermanence = ShortcutPermanence.Temporary;
|
private ShortcutPermanence _displayPermanence = ShortcutPermanence.Temporary;
|
||||||
private ShortcutPermanence _audioPermanence = ShortcutPermanence.Temporary;
|
private ShortcutPermanence _audioPermanence = ShortcutPermanence.Temporary;
|
||||||
private ShortcutPermanence _capturePermanence = ShortcutPermanence.Temporary;
|
private ShortcutPermanence _capturePermanence = ShortcutPermanence.Temporary;
|
||||||
private Hotkey _hotkey = null;
|
private Keys _hotkey = Keys.None;
|
||||||
private bool _autoName = true;
|
private bool _autoName = true;
|
||||||
private ShortcutValidity _isValid;
|
private ShortcutValidity _isValid;
|
||||||
private List<ShortcutError> _shortcutErrors = new List<ShortcutError>();
|
private List<ShortcutError> _shortcutErrors = new List<ShortcutError>();
|
||||||
@ -967,7 +967,7 @@ namespace DisplayMagician
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS3003 // Type is not CLS-compliant
|
#pragma warning disable CS3003 // Type is not CLS-compliant
|
||||||
public Hotkey Hotkey
|
public Keys Hotkey
|
||||||
#pragma warning restore CS3003 // Type is not CLS-compliant
|
#pragma warning restore CS3003 // Type is not CLS-compliant
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -976,8 +976,7 @@ namespace DisplayMagician
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value is Hotkey)
|
_hotkey = value;
|
||||||
_hotkey = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ using DisplayMagicianShared;
|
|||||||
using Manina.Windows.Forms;
|
using Manina.Windows.Forms;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WK.Libraries.HotkeyListenerNS;
|
//using WK.Libraries.HotkeyListenerNS;
|
||||||
|
|
||||||
namespace DisplayMagician.UIForms
|
namespace DisplayMagician.UIForms
|
||||||
{
|
{
|
||||||
@ -467,11 +467,11 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
private void btn_hotkey_Click(object sender, EventArgs e)
|
private void btn_hotkey_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Hotkey testHotkey = null;
|
Keys testHotkey;
|
||||||
if (_selectedProfile.Hotkey is Hotkey)
|
if (_selectedProfile.Hotkey != Keys.None)
|
||||||
testHotkey = _selectedProfile.Hotkey;
|
testHotkey = _selectedProfile.Hotkey;
|
||||||
else
|
else
|
||||||
testHotkey = new Hotkey();
|
testHotkey = Keys.None;
|
||||||
string hotkeyHeading = $"Choose a '{_selectedProfile.Name}' Display Profile 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 +
|
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 +
|
"screen using your keyboard. This must be a Hotkey that" + Environment.NewLine +
|
||||||
@ -496,12 +496,14 @@ namespace DisplayMagician.UIForms
|
|||||||
btn_hotkey.PerformClick();
|
btn_hotkey.PerformClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateHotkeyLabel (Hotkey myHotkey)
|
private void UpdateHotkeyLabel (Keys myHotkey)
|
||||||
{
|
{
|
||||||
// And if we get back and this is a Hotkey with a value, we need to show that in the UI
|
// 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))
|
if (myHotkey != Keys.None)
|
||||||
{
|
{
|
||||||
lbl_hotkey_assigned.Text = "Hotkey: " + HotkeyListener.Convert(myHotkey);
|
KeysConverter kc = new KeysConverter();
|
||||||
|
|
||||||
|
lbl_hotkey_assigned.Text = "Hotkey: " + kc.ConvertToString(myHotkey);
|
||||||
lbl_hotkey_assigned.Visible = true;
|
lbl_hotkey_assigned.Visible = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -7,29 +7,35 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using WK.Libraries.HotkeyListenerNS;
|
//using WK.Libraries.HotkeyListenerNS;
|
||||||
|
using NHotkey.WindowsForms;
|
||||||
|
|
||||||
namespace DisplayMagician.UIForms
|
namespace DisplayMagician.UIForms
|
||||||
{
|
{
|
||||||
public partial class HotkeyForm : Form
|
public partial class HotkeyForm : Form
|
||||||
{
|
{
|
||||||
//HotkeyListener myHotkeyListener = null;
|
//HotkeyListener myHotkeyListener = null;
|
||||||
HotkeySelector hks;
|
//HotkeySelector hks;
|
||||||
Hotkey myHotkey = null;
|
Keys myHotkey = Keys.None;
|
||||||
|
string emptyHotkeyText = "";
|
||||||
|
string invalidHotkeyText = "";
|
||||||
|
List<int> _needNonShiftModifier = new List<int>() { };
|
||||||
|
List<int> _needNonAltGrModifier = new List<int>() { };
|
||||||
|
|
||||||
|
|
||||||
#pragma warning disable CS3003 // Type is not CLS-compliant
|
#pragma warning disable CS3003 // Type is not CLS-compliant
|
||||||
public Hotkey Hotkey
|
public Keys Hotkey
|
||||||
#pragma warning restore CS3003 // Type is not CLS-compliant
|
#pragma warning restore CS3003 // Type is not CLS-compliant
|
||||||
{
|
{
|
||||||
get
|
get;
|
||||||
{
|
/*{
|
||||||
return myHotkey;
|
return myHotkey;
|
||||||
}
|
}*/
|
||||||
set
|
set;
|
||||||
{
|
/*{
|
||||||
if (value is Hotkey)
|
if (value is Keys)
|
||||||
myHotkey = value;
|
myHotkey = value;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,30 +44,20 @@ namespace DisplayMagician.UIForms
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
myHotkey = new Hotkey();
|
//hks = new HotkeySelector();
|
||||||
|
//hks.EmptyHotkeyText = "";
|
||||||
hks = new HotkeySelector();
|
//hks.Enable(txt_hotkey);
|
||||||
hks.EmptyHotkeyText = "";
|
|
||||||
hks.Enable(txt_hotkey);
|
|
||||||
this.ActiveControl = txt_hotkey;
|
this.ActiveControl = txt_hotkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS3001 // Argument type is not CLS-compliant
|
#pragma warning disable CS3001 // Argument type is not CLS-compliant
|
||||||
public HotkeyForm(Hotkey hotkeyToEdit = null, string hotkeyHeading = "", string hotkeyDescription = "")
|
public HotkeyForm(Keys hotkeyToEdit = Keys.None, string hotkeyHeading = "", string hotkeyDescription = "")
|
||||||
#pragma warning restore CS3001 // Argument type is not CLS-compliant
|
#pragma warning restore CS3001 // Argument type is not CLS-compliant
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
//myHotkeyListener = hotkeyListener;
|
myHotkey = hotkeyToEdit;
|
||||||
|
|
||||||
if (hotkeyToEdit == null)
|
|
||||||
myHotkey = new Hotkey();
|
|
||||||
else
|
|
||||||
myHotkey = hotkeyToEdit;
|
|
||||||
|
|
||||||
hks = new HotkeySelector();
|
|
||||||
hks.EmptyHotkeyText = "";
|
|
||||||
hks.Enable(txt_hotkey, hotkeyToEdit);
|
|
||||||
this.ActiveControl = txt_hotkey;
|
this.ActiveControl = txt_hotkey;
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(hotkeyHeading))
|
if (!String.IsNullOrEmpty(hotkeyHeading))
|
||||||
@ -88,34 +84,23 @@ namespace DisplayMagician.UIForms
|
|||||||
private void btn_clear_Click(object sender, EventArgs e)
|
private void btn_clear_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.DialogResult = DialogResult.None;
|
this.DialogResult = DialogResult.None;
|
||||||
hks.Clear(txt_hotkey);
|
txt_hotkey.Text = "";
|
||||||
myHotkey.KeyCode = Keys.None;
|
myHotkey = Keys.None;
|
||||||
myHotkey.Modifiers = Keys.None;
|
|
||||||
this.ActiveControl = txt_hotkey;
|
this.ActiveControl = txt_hotkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btn_save_Click(object sender, EventArgs e)
|
private void btn_save_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!String.IsNullOrWhiteSpace(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
|
else
|
||||||
{
|
{
|
||||||
myHotkey.KeyCode = Keys.None;
|
myHotkey = Keys.None;
|
||||||
myHotkey.Modifiers = Keys.None;
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
this.Hotkey = myHotkey;
|
this.Hotkey = myHotkey;
|
||||||
this.DialogResult = DialogResult.OK;
|
this.DialogResult = DialogResult.OK;
|
||||||
this.Close();
|
this.Close();
|
||||||
@ -126,5 +111,185 @@ namespace DisplayMagician.UIForms
|
|||||||
this.DialogResult = DialogResult.Cancel;
|
this.DialogResult = DialogResult.Cancel;
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires when a key is pressed down. Here, we'll want to update the Text
|
||||||
|
/// property to notify the user what key combination is currently pressed.
|
||||||
|
/// </summary>
|
||||||
|
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.KeyData == Keys.Delete || e.KeyData == (Keys.Control | Keys.Delete))
|
||||||
|
{
|
||||||
|
myHotkey = Keys.None;
|
||||||
|
Refresh(txt_hotkey, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (e.KeyData == (Keys.Shift | Keys.Insert))
|
||||||
|
{
|
||||||
|
myHotkey = Keys.Shift;
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the current hotkey.
|
||||||
|
if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
|
||||||
|
{
|
||||||
|
myHotkey = Keys.None;
|
||||||
|
Refresh(txt_hotkey, false);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myHotkey = e.KeyCode;
|
||||||
|
|
||||||
|
Refresh(txt_hotkey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires when all keys are released. If the current hotkey isn't valid, reset it.
|
||||||
|
/// Otherwise, do nothing and keep the Text and hotkey as it was.
|
||||||
|
/// </summary>
|
||||||
|
private void OnKeyUp(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (myHotkey == Keys.None && Control.ModifierKeys == Keys.None)
|
||||||
|
{
|
||||||
|
myHotkey = Keys.None;
|
||||||
|
Refresh(txt_hotkey, false);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prevents anything entered in Input controls from being displayed.
|
||||||
|
/// Without this, a "A" key press would appear as "aControl, Alt + A".
|
||||||
|
/// </summary>
|
||||||
|
private void OnKeyPress(object sender, KeyPressEventArgs e)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Refresh(Control control, bool internalCall)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string parsedHotkey = string.Empty;
|
||||||
|
|
||||||
|
// No hotkey set.
|
||||||
|
if (myHotkey == Keys.None)
|
||||||
|
{
|
||||||
|
txt_hotkey.Text = emptyHotkeyText;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LWin/RWin don't work as hotkeys...
|
||||||
|
// (neither do they work as modifier keys in .NET 2.0).
|
||||||
|
if (myHotkey == Keys.LWin || myHotkey == Keys.RWin)
|
||||||
|
{
|
||||||
|
txt_hotkey.Text = invalidHotkeyText;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only validate input if it comes from the user.
|
||||||
|
if (internalCall == false)
|
||||||
|
{
|
||||||
|
// No modifier or shift only, and a hotkey that needs another modifier.
|
||||||
|
if ((myHotkey == Keys.Shift || myHotkey == Keys.None) &&
|
||||||
|
this._needNonShiftModifier.Contains((int)myHotkey))
|
||||||
|
{
|
||||||
|
if (this.myHotkey == Keys.None)
|
||||||
|
{
|
||||||
|
// Set Ctrl+Alt as the modifier unless Ctrl+Alt+<key> won't work.
|
||||||
|
if (_needNonAltGrModifier.Contains((int)myHotkey) == false)
|
||||||
|
{
|
||||||
|
this.myHotkey |= Keys.Alt | Keys.Control;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ...In that case, use Shift+Alt instead.
|
||||||
|
this.myHotkey |= Keys.Alt | Keys.Shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// User pressed Shift and an invalid key (e.g. a letter or a number),
|
||||||
|
// that needs another set of modifier keys.
|
||||||
|
this.myHotkey = Keys.None;
|
||||||
|
|
||||||
|
txt_hotkey.Text = this.myHotkey.ToString() + $" + {invalidHotkeyText}";
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Without this code, pressing only Ctrl
|
||||||
|
// will show up as "Control + ControlKey", etc.
|
||||||
|
if (this.myHotkey == Keys.Menu || /* Alt */
|
||||||
|
this.myHotkey == Keys.ShiftKey ||
|
||||||
|
this.myHotkey == Keys.ControlKey)
|
||||||
|
{
|
||||||
|
this.myHotkey = Keys.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A final compilation of the processed keys in string format.
|
||||||
|
parsedHotkey = this.myHotkey.ToString();
|
||||||
|
|
||||||
|
txt_hotkey.Text = parsedHotkey;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateInvalidModifiers()
|
||||||
|
{
|
||||||
|
// Fill the ArrayLists that contain
|
||||||
|
// all invalid hotkey combinations.
|
||||||
|
_needNonShiftModifier = new List<int>() { };
|
||||||
|
_needNonAltGrModifier = new List<int>() { };
|
||||||
|
|
||||||
|
// Shift + 0 - 9, A - Z.
|
||||||
|
for (Keys k = Keys.D0; k <= Keys.Z; k++)
|
||||||
|
_needNonShiftModifier.Add((int)k);
|
||||||
|
|
||||||
|
// Shift + Numpad keys.
|
||||||
|
for (Keys k = Keys.NumPad0; k <= Keys.NumPad9; k++)
|
||||||
|
_needNonShiftModifier.Add((int)k);
|
||||||
|
|
||||||
|
// Shift + Misc (,;<./ etc).
|
||||||
|
for (Keys k = Keys.Oem1; k <= Keys.OemBackslash; k++)
|
||||||
|
_needNonShiftModifier.Add((int)k);
|
||||||
|
|
||||||
|
// Shift + Space, PgUp, PgDn, End, Home.
|
||||||
|
for (Keys k = Keys.Space; k <= Keys.Home; k++)
|
||||||
|
_needNonShiftModifier.Add((int)k);
|
||||||
|
|
||||||
|
// Misc keys that we can't loop through.
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Insert);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Help);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Multiply);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Add);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Subtract);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Divide);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Decimal);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Return);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Escape);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.NumLock);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Scroll);
|
||||||
|
_needNonShiftModifier.Add((int)Keys.Pause);
|
||||||
|
|
||||||
|
// Ctrl+Alt + 0 - 9.
|
||||||
|
for (Keys k = Keys.D0; k <= Keys.D9; k++)
|
||||||
|
_needNonAltGrModifier.Add((int)k);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,10 @@ using Newtonsoft.Json;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Windows.Data.Xml.Dom;
|
using Windows.Data.Xml.Dom;
|
||||||
using Microsoft.Toolkit.Uwp.Notifications;
|
using Microsoft.Toolkit.Uwp.Notifications;
|
||||||
using WK.Libraries.HotkeyListenerNS;
|
//using WK.Libraries.HotkeyListenerNS;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NHotkey.WindowsForms;
|
||||||
|
using NHotkey;
|
||||||
|
|
||||||
namespace DisplayMagician.UIForms
|
namespace DisplayMagician.UIForms
|
||||||
{
|
{
|
||||||
@ -20,12 +22,12 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
private bool allowVisible; // ContextMenu's Show command used
|
private bool allowVisible; // ContextMenu's Show command used
|
||||||
private bool allowClose; // ContextMenu's Exit command used
|
private bool allowClose; // ContextMenu's Exit command used
|
||||||
private HotkeyListener hotkeyListener = new HotkeyListener();
|
/*private HotkeyListener hotkeyListener = new HotkeyListener();
|
||||||
private Hotkey hotkeyMainWindow;
|
private Hotkey hotkeyMainWindow;
|
||||||
private Hotkey hotkeyShortcutLibraryWindow;
|
private Hotkey hotkeyShortcutLibraryWindow;
|
||||||
private Hotkey hotkeyDisplayProfileWindow;
|
private Hotkey hotkeyDisplayProfileWindow;*/
|
||||||
private Dictionary<Hotkey, string> hotkeyDisplayProfiles = new Dictionary<Hotkey, string>() { };
|
private List<string> hotkeyDisplayProfiles = new List<string>() { };
|
||||||
private Dictionary<Hotkey, string> hotkeyShortcuts = new Dictionary<Hotkey, string>() { };
|
private List<string> hotkeyShortcuts = new List<string>() { };
|
||||||
|
|
||||||
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
@ -39,38 +41,33 @@ namespace DisplayMagician.UIForms
|
|||||||
notifyIcon.ContextMenuStrip = mainContextMenuStrip;
|
notifyIcon.ContextMenuStrip = mainContextMenuStrip;
|
||||||
RefreshNotifyIconMenus();
|
RefreshNotifyIconMenus();
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
/*if (Program.AppProgramSettings.MainWindowHotkey)
|
/*if (Program.AppProgramSettings.MainWindowHotkey)
|
||||||
hotkeyMainWindow = new Hotkey(Program.AppProgramSettings.MainWindowHotkey);
|
HotkeyManager.Current.AddOrReplace("MainWindowHotkey", Program.AppProgramSettings.MainWindowHotkey, OnWindowHotkeyPressed);
|
||||||
if (Program.AppProgramSettings.ShortcutLibraryWindow)
|
if (Program.AppProgramSettings.ShortcutLibraryWindow)
|
||||||
hotkeyShortcutLibraryWindow = new Hotkey(Program.AppProgramSettings.ShortcutLibraryWindow);
|
HotkeyManager.Current.AddOrReplace("ShortcutLibraryWindow", Program.AppProgramSettings.ShortcutLibraryWindow, OnWindowHotkeyPressed);
|
||||||
if (Program.AppProgramSettings.DisplayProfileWindow)
|
if (Program.AppProgramSettings.DisplayProfileWindow)
|
||||||
hotkeyDisplayProfileWindow = new Hotkey(Program.AppProgramSettings.DisplayProfileWindow);*/
|
HotkeyManager.Current.AddOrReplace("DisplayProfileWindow", Program.AppProgramSettings.DisplayProfileWindow, OnWindowHotkeyPressed);*/
|
||||||
|
|
||||||
// Add all the Profile Hotkeys that are set
|
// Add all the Profile Hotkeys that are set
|
||||||
foreach (ProfileItem myProfile in ProfileRepository.AllProfiles)
|
foreach (ProfileItem myProfile in ProfileRepository.AllProfiles)
|
||||||
{
|
{
|
||||||
if (myProfile.Hotkey is Hotkey && myProfile.Hotkey.Modifiers != Keys.None && myProfile.Hotkey.KeyCode != Keys.None)
|
if (myProfile.Hotkey != Keys.None)
|
||||||
{
|
{
|
||||||
hotkeyDisplayProfiles.Add(myProfile.Hotkey, myProfile.UUID);
|
hotkeyDisplayProfiles.Add(myProfile.UUID);
|
||||||
|
HotkeyManager.Current.AddOrReplace(myProfile.UUID, myProfile.Hotkey, OnWindowHotkeyPressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all the Shortcut Hotkeys that are set
|
// Add all the Shortcut Hotkeys that are set
|
||||||
foreach (ShortcutItem myShortcut in ShortcutRepository.AllShortcuts)
|
foreach (ShortcutItem myShortcut in ShortcutRepository.AllShortcuts)
|
||||||
{
|
{
|
||||||
if (myShortcut.Hotkey is Hotkey && myShortcut.Hotkey.Modifiers != Keys.None && myShortcut.Hotkey.KeyCode != Keys.None)
|
if (myShortcut.Hotkey != Keys.None)
|
||||||
{
|
{
|
||||||
hotkeyShortcuts.Add(myShortcut.Hotkey, myShortcut.UUID);
|
hotkeyShortcuts.Add(myShortcut.UUID);
|
||||||
|
HotkeyManager.Current.AddOrReplace(myShortcut.UUID, myShortcut.Hotkey, OnWindowHotkeyPressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// And now connect up our processing function
|
// And now connect up our processing function
|
||||||
Program.HotkeyListener.HotkeyPressed += Hkl_WindowHotkeyPressed;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -536,28 +533,29 @@ namespace DisplayMagician.UIForms
|
|||||||
openApplicationWindow();
|
openApplicationWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Hkl_WindowHotkeyPressed(object sender, HotkeyEventArgs e)
|
private void OnWindowHotkeyPressed(object sender, HotkeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Hotkey == hotkeyMainWindow)
|
if (e.Name == "HotkeyMainWindow")
|
||||||
openApplicationWindow();
|
openApplicationWindow();
|
||||||
else if (e.Hotkey == hotkeyDisplayProfileWindow)
|
else if (e.Name == "HotkeyDisplayProfileWindow")
|
||||||
btn_setup_display_profiles.PerformClick();
|
btn_setup_display_profiles.PerformClick();
|
||||||
else if (e.Hotkey == hotkeyDisplayProfileWindow)
|
else if (e.Name == "ShortcutLibraryWindow")
|
||||||
btn_setup_game_shortcuts.PerformClick();
|
btn_setup_game_shortcuts.PerformClick();
|
||||||
else if (hotkeyDisplayProfiles.ContainsKey(e.Hotkey))
|
else if (hotkeyDisplayProfiles.Contains(e.Name))
|
||||||
{
|
{
|
||||||
string displayProfileUUID = hotkeyDisplayProfiles[e.Hotkey];
|
string displayProfileUUID = e.Name;
|
||||||
ProfileItem chosenProfile = ProfileRepository.GetProfile(displayProfileUUID);
|
ProfileItem chosenProfile = ProfileRepository.GetProfile(displayProfileUUID);
|
||||||
if (chosenProfile is ProfileItem)
|
if (chosenProfile is ProfileItem)
|
||||||
Program.ApplyProfile(chosenProfile);
|
Program.ApplyProfile(chosenProfile);
|
||||||
}
|
}
|
||||||
else if (hotkeyShortcuts.ContainsKey(e.Hotkey))
|
else if (hotkeyShortcuts.Contains(e.Name))
|
||||||
{
|
{
|
||||||
string shortcutUUID = hotkeyShortcuts[e.Hotkey];
|
string shortcutUUID = e.Name;
|
||||||
ShortcutItem chosenShortcut = ShortcutRepository.GetShortcut(shortcutUUID);
|
ShortcutItem chosenShortcut = ShortcutRepository.GetShortcut(shortcutUUID);
|
||||||
if (chosenShortcut is ShortcutItem)
|
if (chosenShortcut is ShortcutItem)
|
||||||
ShortcutRepository.RunShortcut(chosenShortcut);
|
ShortcutRepository.RunShortcut(chosenShortcut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ using Manina.Windows.Forms;
|
|||||||
using System.Windows.Forms.VisualStyles;
|
using System.Windows.Forms.VisualStyles;
|
||||||
using AudioSwitcher.AudioApi.CoreAudio;
|
using AudioSwitcher.AudioApi.CoreAudio;
|
||||||
using AudioSwitcher.AudioApi;
|
using AudioSwitcher.AudioApi;
|
||||||
using WK.Libraries.HotkeyListenerNS;
|
//using WK.Libraries.HotkeyListenerNS;
|
||||||
|
|
||||||
namespace DisplayMagician.UIForms
|
namespace DisplayMagician.UIForms
|
||||||
{
|
{
|
||||||
@ -2230,11 +2230,11 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
private void btn_hotkey_Click(object sender, EventArgs e)
|
private void btn_hotkey_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Hotkey testHotkey = null;
|
Keys testHotkey;
|
||||||
if (_shortcutToEdit.Hotkey is Hotkey)
|
if (_shortcutToEdit.Hotkey != Keys.None)
|
||||||
testHotkey = _shortcutToEdit.Hotkey;
|
testHotkey = _shortcutToEdit.Hotkey;
|
||||||
else
|
else
|
||||||
testHotkey = new Hotkey();
|
testHotkey = Keys.None;
|
||||||
string hotkeyHeading = $"Choose a '{_shortcutToEdit.Name}' Shortcut 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 +
|
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 +
|
"game shortcut using your keyboard. This must be a Hotkey that" + Environment.NewLine +
|
||||||
@ -2257,12 +2257,14 @@ namespace DisplayMagician.UIForms
|
|||||||
btn_hotkey.PerformClick();
|
btn_hotkey.PerformClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateHotkeyLabel(Hotkey myHotkey)
|
private void UpdateHotkeyLabel(Keys myHotkey)
|
||||||
{
|
{
|
||||||
// And if we get back and this is a Hotkey with a value, we need to show that in the UI
|
// 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))
|
if (myHotkey != Keys.None)
|
||||||
{
|
{
|
||||||
lbl_hotkey_assigned.Text = "Hotkey: " + HotkeyListener.Convert(myHotkey);
|
KeysConverter kc = new KeysConverter();
|
||||||
|
|
||||||
|
lbl_hotkey_assigned.Text = "Hotkey: " + kc.ConvertToString(myHotkey);
|
||||||
lbl_hotkey_assigned.Visible = true;
|
lbl_hotkey_assigned.Visible = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -9,7 +9,7 @@ using System.Drawing;
|
|||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using IWshRuntimeLibrary;
|
using IWshRuntimeLibrary;
|
||||||
using WK.Libraries.HotkeyListenerNS;
|
//using WK.Libraries.HotkeyListenerNS;
|
||||||
|
|
||||||
namespace DisplayMagicianShared
|
namespace DisplayMagicianShared
|
||||||
{
|
{
|
||||||
@ -25,7 +25,7 @@ namespace DisplayMagicianShared
|
|||||||
|
|
||||||
private string _uuid = "";
|
private string _uuid = "";
|
||||||
private bool _isPossible = false;
|
private bool _isPossible = false;
|
||||||
private Hotkey _hotkey = null;
|
private Keys _hotkey = Keys.None;
|
||||||
|
|
||||||
|
|
||||||
#region JsonConverterBitmap
|
#region JsonConverterBitmap
|
||||||
@ -152,15 +152,14 @@ namespace DisplayMagicianShared
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hotkey Hotkey {
|
public Keys Hotkey {
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _hotkey;
|
return _hotkey;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value is Hotkey)
|
_hotkey = value;
|
||||||
_hotkey = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user