mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Custom keybinds for performance modes
This commit is contained in:
@@ -60,11 +60,11 @@ public class ASUSWmi
|
|||||||
public const int GPUModeUltimate = 2;
|
public const int GPUModeUltimate = 2;
|
||||||
|
|
||||||
|
|
||||||
public const int MaxTotal = 180;
|
public const int MaxTotal = 200;
|
||||||
public const int MinTotal = 5;
|
public const int MinTotal = 5;
|
||||||
public const int DefaultTotal = 125;
|
public const int DefaultTotal = 125;
|
||||||
|
|
||||||
public const int MaxCPU = 90;
|
public const int MaxCPU = 130;
|
||||||
public const int MinCPU = 5;
|
public const int MinCPU = 5;
|
||||||
public const int DefaultCPU = 80;
|
public const int DefaultCPU = 80;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using GHelper;
|
using GHelper;
|
||||||
using GHelper.Gpu;
|
using GHelper.Gpu;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Management;
|
||||||
|
|
||||||
public static class HardwareMonitor
|
public static class HardwareMonitor
|
||||||
{
|
{
|
||||||
@@ -62,6 +63,7 @@ public static class HardwareMonitor
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void ReadSensors()
|
public static void ReadSensors()
|
||||||
{
|
{
|
||||||
batteryDischarge = -1;
|
batteryDischarge = -1;
|
||||||
|
|||||||
@@ -1,12 +1,53 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using static Tools.ScreenInterrogatory;
|
using static Tools.ScreenInterrogatory;
|
||||||
|
|
||||||
namespace Tools
|
namespace Tools
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public class KeyHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public const int NOMOD = 0x0000;
|
||||||
|
public const int ALT = 0x0001;
|
||||||
|
public const int CTRL = 0x0002;
|
||||||
|
public const int SHIFT = 0x0004;
|
||||||
|
public const int WIN = 0x0008;
|
||||||
|
|
||||||
|
public const int WM_HOTKEY_MSG_ID = 0x0312;
|
||||||
|
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
||||||
|
|
||||||
|
private int modifier;
|
||||||
|
private int key;
|
||||||
|
private IntPtr hWnd;
|
||||||
|
private int id;
|
||||||
|
public KeyHandler(int modifier, Keys key, nint handle)
|
||||||
|
{
|
||||||
|
this.modifier = modifier;
|
||||||
|
this.key = (int)key;
|
||||||
|
this.hWnd = handle;
|
||||||
|
id = this.GetHashCode();
|
||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return modifier ^ key ^ hWnd.ToInt32();
|
||||||
|
}
|
||||||
|
public bool Register()
|
||||||
|
{
|
||||||
|
return RegisterHotKey(hWnd, id, modifier, key);
|
||||||
|
}
|
||||||
|
public bool Unregiser()
|
||||||
|
{
|
||||||
|
return UnregisterHotKey(hWnd, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class ScreenInterrogatory
|
public static class ScreenInterrogatory
|
||||||
{
|
{
|
||||||
public const int ERROR_SUCCESS = 0;
|
public const int ERROR_SUCCESS = 0;
|
||||||
@@ -608,7 +649,8 @@ public class NativeMethods
|
|||||||
if (dm.dmDisplayFrequency > frequency) frequency = dm.dmDisplayFrequency;
|
if (dm.dmDisplayFrequency > frequency) frequency = dm.dmDisplayFrequency;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
|
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
|
using Tools;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
@@ -57,7 +58,7 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.WriteLine("------------");
|
Logger.WriteLine("------------");
|
||||||
Logger.WriteLine("App launched");
|
Logger.WriteLine("App launched: " + config.GetModel());
|
||||||
|
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
|
|
||||||
@@ -84,6 +85,9 @@ namespace GHelper
|
|||||||
var settingGuid = new NativeMethods.PowerSettingGuid();
|
var settingGuid = new NativeMethods.PowerSettingGuid();
|
||||||
unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
|
unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||||
|
|
||||||
|
// CTRL + SHIFT + F5 to cycle profiles
|
||||||
|
var ghk = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, Keys.F5, ds);
|
||||||
|
ghk.Register();
|
||||||
|
|
||||||
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\'))
|
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\'))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Drawing.Imaging;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
using Tools;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
@@ -27,6 +28,9 @@ namespace GHelper
|
|||||||
static AnimeMatrixDevice mat;
|
static AnimeMatrixDevice mat;
|
||||||
static long lastRefresh;
|
static long lastRefresh;
|
||||||
|
|
||||||
|
private bool customFans = false;
|
||||||
|
private int customPower = 0;
|
||||||
|
|
||||||
public SettingsForm()
|
public SettingsForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -185,7 +189,7 @@ namespace GHelper
|
|||||||
|
|
||||||
private static void TrayIcon_MouseMove(object? sender, MouseEventArgs e)
|
private static void TrayIcon_MouseMove(object? sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
Program.settingsForm.RefreshSensors();
|
Program.settingsForm.RefreshSensors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -231,7 +235,7 @@ namespace GHelper
|
|||||||
|
|
||||||
private void ButtonOptimized_MouseHover(object? sender, EventArgs e)
|
private void ButtonOptimized_MouseHover(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
labelTipGPU.Text = "Switch to Eco on battery and to Standard when plugged";
|
labelTipGPU.Text = "Sptch to Eco on battery and to Standard when plugged";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonGPU_MouseLeave(object? sender, EventArgs e)
|
private void ButtonGPU_MouseLeave(object? sender, EventArgs e)
|
||||||
@@ -280,6 +284,9 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
m.Result = (IntPtr)1;
|
m.Result = (IntPtr)1;
|
||||||
break;
|
break;
|
||||||
|
case KeyHandler.WM_HOTKEY_MSG_ID:
|
||||||
|
CyclePerformanceMode();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
base.WndProc(ref m);
|
base.WndProc(ref m);
|
||||||
}
|
}
|
||||||
@@ -854,13 +861,17 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void SetPerformanceLabel()
|
||||||
|
{
|
||||||
|
labelPerf.Text = "Performance Mode" + (customFans?"+":"") + ((customPower > 0) ? " "+customPower+"W" : "");
|
||||||
|
}
|
||||||
|
|
||||||
public void SetPower()
|
public void SetPower()
|
||||||
{
|
{
|
||||||
int limit_total = Program.config.getConfigPerf("limit_total");
|
int limit_total = Program.config.getConfigPerf("limit_total");
|
||||||
int limit_cpu = Program.config.getConfigPerf("limit_cpu");
|
int limit_cpu = Program.config.getConfigPerf("limit_cpu");
|
||||||
|
|
||||||
string limitLabel = null;
|
|
||||||
|
|
||||||
if (limit_total > ASUSWmi.MaxTotal) return;
|
if (limit_total > ASUSWmi.MaxTotal) return;
|
||||||
if (limit_total < ASUSWmi.MinTotal) return;
|
if (limit_total < ASUSWmi.MinTotal) return;
|
||||||
|
|
||||||
@@ -870,25 +881,23 @@ namespace GHelper
|
|||||||
if (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0)
|
if (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0)
|
||||||
{
|
{
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total, "PowerLimit A");
|
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total, "PowerLimit A");
|
||||||
limitLabel = limit_total + "W";
|
customPower = limit_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0)
|
if (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0)
|
||||||
{
|
{
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu, "PowerLimit B");
|
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu, "PowerLimit B");
|
||||||
limitLabel = limit_cpu + "W";
|
customPower = limit_cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
Program.settingsForm.BeginInvoke(delegate
|
Program.settingsForm.BeginInvoke(SetPerformanceLabel);
|
||||||
{
|
|
||||||
labelPerf.Text = "Performance Mode+ " + limitLabel;
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void AutoFans()
|
public void AutoFans()
|
||||||
{
|
{
|
||||||
|
customFans = false;
|
||||||
|
|
||||||
if (Program.config.getConfigPerf("auto_apply") == 1)
|
if (Program.config.getConfigPerf("auto_apply") == 1)
|
||||||
{
|
{
|
||||||
@@ -904,16 +913,18 @@ namespace GHelper
|
|||||||
Logger.WriteLine("Driver rejected fan curve, resetting mode to " + mode);
|
Logger.WriteLine("Driver rejected fan curve, resetting mode to " + mode);
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, mode, "PerformanceMode");
|
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, mode, "PerformanceMode");
|
||||||
}
|
}
|
||||||
else
|
else customFans = true;
|
||||||
labelPerf.Text = "Performance Mode+";
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
labelPerf.Text = "Performance Mode";
|
Program.settingsForm.BeginInvoke(SetPerformanceLabel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AutoPower(int delay = 0)
|
public void AutoPower(int delay = 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
customPower = 0;
|
||||||
|
|
||||||
if (Program.config.getConfigPerf("auto_apply_power") == 1)
|
if (Program.config.getConfigPerf("auto_apply_power") == 1)
|
||||||
{
|
{
|
||||||
if (delay > 0)
|
if (delay > 0)
|
||||||
@@ -1003,15 +1014,19 @@ namespace GHelper
|
|||||||
fans.InitPower();
|
fans.InitPower();
|
||||||
fans.InitBoost();
|
fans.InitBoost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void CyclePerformanceMode()
|
public void CyclePerformanceMode()
|
||||||
{
|
{
|
||||||
SetPerformanceMode(Program.config.getConfig("performance_mode") + 1, true);
|
int mode = Program.config.getConfig("performance_mode");
|
||||||
|
|
||||||
|
if (Control.ModifierKeys == Keys.Shift)
|
||||||
|
mode = (mode == 0) ? 2 : mode - 1;
|
||||||
|
else
|
||||||
|
mode++;
|
||||||
|
|
||||||
|
SetPerformanceMode(mode, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1021,10 +1036,10 @@ namespace GHelper
|
|||||||
|
|
||||||
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
|
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
|
||||||
Aura.ApplyBrightness(3);
|
Aura.ApplyBrightness(3);
|
||||||
//Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Up);
|
//Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Up);
|
||||||
else
|
else
|
||||||
Aura.ApplyBrightness(0);
|
Aura.ApplyBrightness(0);
|
||||||
//Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Down);
|
//Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Down);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user