From 80e3971dad9427bb3059a0d0d05c2b7e5e0c747e Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 21 May 2023 20:44:04 +0200 Subject: [PATCH] m1,m2 bindings --- app/Extra.cs | 4 ++++ app/InputDispatcher.cs | 49 ++++++++++++++++++++++++++++++++---------- app/Settings.cs | 24 +++++++++++++++++---- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/app/Extra.cs b/app/Extra.cs index 6855c4b7..baaff4fa 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -56,6 +56,10 @@ namespace GHelper { if (combo.SelectedValue is not null) AppConfig.setConfig(name, combo.SelectedValue.ToString()); + + if (name == "m1" || name == "m2") + Program.inputDispatcher.RegisterKeys(); + }; txbox.Text = AppConfig.getConfigString(name + "_custom"); diff --git a/app/InputDispatcher.cs b/app/InputDispatcher.cs index e15b49dc..558fb4e9 100644 --- a/app/InputDispatcher.cs +++ b/app/InputDispatcher.cs @@ -3,6 +3,7 @@ using NAudio.CoreAudioApi; using System.Diagnostics; using System.Management; using Tools; +using static NativeMethods; namespace GHelper { @@ -12,6 +13,10 @@ namespace GHelper private static bool isOptimizationRunning = OptimizationService.IsRunning(); private static nint windowHandle; + public static Keys keyProfile = Keys.F5; + + KeyHandler m1, m2, togggle; + public InputDispatcher(nint handle) { @@ -22,19 +27,39 @@ namespace GHelper if (!isOptimizationRunning) AsusUSB.RunListener(HandleEvent); // CTRL + SHIFT + F5 to cycle profiles - Keys keybind_profile = (AppConfig.getConfig("keybind_profile") != -1) ? (Keys)AppConfig.getConfig("keybind_profile") : Keys.F5; - if (keybind_profile != 0) + if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile"); + + togggle = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, keyProfile, windowHandle); + m1 = new KeyHandler(KeyHandler.NOMOD, Keys.VolumeDown, windowHandle); + m2 = new KeyHandler(KeyHandler.NOMOD, Keys.VolumeUp, windowHandle); + + RegisterKeys(); + } + + public void RegisterKeys() + { + + string actionM1 = AppConfig.getConfigString("m1"); + string actionM2 = AppConfig.getConfigString("m2"); + + togggle.Unregiser(); + m1.Unregiser(); + m2.Unregiser(); + + if (keyProfile != Keys.None) { - KeyHandler ghk = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, keybind_profile, windowHandle); - ghk.Register(); + togggle.Register(); } - /* - KeyHandler m1 = new KeyHandler(0, Keys.VolumeDown, ds); - m1.Register(); - KeyHandler m2 = new KeyHandler(0, Keys.VolumeUp, ds); - m2.Register(); - */ + if (actionM1 is not null && actionM1.Length > 0) + { + m1.Register(); + } + + if (actionM2 is not null && actionM2.Length > 0) + { + m2.Register(); + } } @@ -60,7 +85,7 @@ namespace GHelper } - static void KeyProcess(string name = "m3") + public static void KeyProcess(string name = "m3") { string action = AppConfig.getConfigString(name); @@ -70,6 +95,8 @@ namespace GHelper action = "ghelper"; if (name == "fnf4") action = "aura"; + if (name == "fnf5") + action = "performance"; if (name == "m3" && !isOptimizationRunning) action = "micmute"; } diff --git a/app/Settings.cs b/app/Settings.cs index 05d6f161..2edb3d95 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -6,7 +6,6 @@ using System.Net; using System.Reflection; using System.Text.Json; using System.Timers; -using System.Windows.Forms; using Tools; namespace GHelper @@ -471,7 +470,7 @@ namespace GHelper if (!buttonXGM.Visible) return; - labelTipGPU.Text = buttonXGM.Bounds.Contains(table.PointToClient(Cursor.Position)) ? + labelTipGPU.Text = buttonXGM.Bounds.Contains(table.PointToClient(Cursor.Position)) ? "XGMobile toggle works only in Standard mode" : ""; } @@ -517,8 +516,24 @@ namespace GHelper } m.Result = (IntPtr)1; break; + case KeyHandler.WM_HOTKEY_MSG_ID: - CyclePerformanceMode(); + + Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); + + switch (key) + { + case Keys.VolumeDown: + InputDispatcher.KeyProcess("m1"); + break; + case Keys.VolumeUp: + InputDispatcher.KeyProcess("m2"); + break; + default: + if (key == InputDispatcher.keyProfile) CyclePerformanceMode(); + break; + } + break; } base.WndProc(ref m); @@ -1384,7 +1399,8 @@ namespace GHelper ButtonEnabled(buttonEco, false); ButtonEnabled(buttonStandard, false); ButtonEnabled(buttonUltimate, false); - } else + } + else { ButtonEnabled(buttonOptimized, true); ButtonEnabled(buttonEco, true);