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 MaxTotal = 180;
|
||||
public const int MaxTotal = 200;
|
||||
public const int MinTotal = 5;
|
||||
public const int DefaultTotal = 125;
|
||||
|
||||
public const int MaxCPU = 90;
|
||||
public const int MaxCPU = 130;
|
||||
public const int MinCPU = 5;
|
||||
public const int DefaultCPU = 80;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using GHelper;
|
||||
using GHelper.Gpu;
|
||||
using System.Diagnostics;
|
||||
using System.Management;
|
||||
|
||||
public static class HardwareMonitor
|
||||
{
|
||||
@@ -62,6 +63,7 @@ public static class HardwareMonitor
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static void ReadSensors()
|
||||
{
|
||||
batteryDischarge = -1;
|
||||
|
||||
@@ -1,12 +1,53 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Xml.Linq;
|
||||
using static Tools.ScreenInterrogatory;
|
||||
|
||||
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 const int ERROR_SUCCESS = 0;
|
||||
@@ -608,7 +649,8 @@ public class NativeMethods
|
||||
if (dm.dmDisplayFrequency > frequency) frequency = dm.dmDisplayFrequency;
|
||||
i++;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Win32;
|
||||
using System.Diagnostics;
|
||||
using System.Management;
|
||||
using Tools;
|
||||
|
||||
namespace GHelper
|
||||
{
|
||||
@@ -57,7 +58,7 @@ namespace GHelper
|
||||
}
|
||||
|
||||
Logger.WriteLine("------------");
|
||||
Logger.WriteLine("App launched");
|
||||
Logger.WriteLine("App launched: " + config.GetModel());
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
|
||||
@@ -84,6 +85,9 @@ namespace GHelper
|
||||
var settingGuid = new NativeMethods.PowerSettingGuid();
|
||||
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('\\'))
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Timers;
|
||||
using Tools;
|
||||
|
||||
namespace GHelper
|
||||
{
|
||||
@@ -27,6 +28,9 @@ namespace GHelper
|
||||
static AnimeMatrixDevice mat;
|
||||
static long lastRefresh;
|
||||
|
||||
private bool customFans = false;
|
||||
private int customPower = 0;
|
||||
|
||||
public SettingsForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -231,7 +235,7 @@ namespace GHelper
|
||||
|
||||
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)
|
||||
@@ -280,6 +284,9 @@ namespace GHelper
|
||||
}
|
||||
m.Result = (IntPtr)1;
|
||||
break;
|
||||
case KeyHandler.WM_HOTKEY_MSG_ID:
|
||||
CyclePerformanceMode();
|
||||
break;
|
||||
}
|
||||
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()
|
||||
{
|
||||
int limit_total = Program.config.getConfigPerf("limit_total");
|
||||
int limit_cpu = Program.config.getConfigPerf("limit_cpu");
|
||||
|
||||
string limitLabel = null;
|
||||
|
||||
if (limit_total > ASUSWmi.MaxTotal) return;
|
||||
if (limit_total < ASUSWmi.MinTotal) return;
|
||||
|
||||
@@ -870,25 +881,23 @@ namespace GHelper
|
||||
if (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu, "PowerLimit B");
|
||||
limitLabel = limit_cpu + "W";
|
||||
customPower = limit_cpu;
|
||||
}
|
||||
|
||||
Program.settingsForm.BeginInvoke(delegate
|
||||
{
|
||||
labelPerf.Text = "Performance Mode+ " + limitLabel;
|
||||
});
|
||||
Program.settingsForm.BeginInvoke(SetPerformanceLabel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void AutoFans()
|
||||
{
|
||||
customFans = false;
|
||||
|
||||
if (Program.config.getConfigPerf("auto_apply") == 1)
|
||||
{
|
||||
@@ -904,16 +913,18 @@ namespace GHelper
|
||||
Logger.WriteLine("Driver rejected fan curve, resetting mode to " + mode);
|
||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, mode, "PerformanceMode");
|
||||
}
|
||||
else
|
||||
labelPerf.Text = "Performance Mode+";
|
||||
else customFans = true;
|
||||
}
|
||||
else
|
||||
labelPerf.Text = "Performance Mode";
|
||||
|
||||
Program.settingsForm.BeginInvoke(SetPerformanceLabel);
|
||||
|
||||
}
|
||||
|
||||
public void AutoPower(int delay = 0)
|
||||
{
|
||||
|
||||
customPower = 0;
|
||||
|
||||
if (Program.config.getConfigPerf("auto_apply_power") == 1)
|
||||
{
|
||||
if (delay > 0)
|
||||
@@ -1003,15 +1014,19 @@ namespace GHelper
|
||||
fans.InitPower();
|
||||
fans.InitBoost();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user