mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Tweaks and fixes
This commit is contained in:
@@ -71,11 +71,11 @@ public static class AppConfig
|
|||||||
File.WriteAllText(configFile, jsonString);
|
File.WriteAllText(configFile, jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getConfig(string name)
|
public static int getConfig(string name, int empty = -1)
|
||||||
{
|
{
|
||||||
if (config.ContainsKey(name))
|
if (config.ContainsKey(name))
|
||||||
return int.Parse(config[name].ToString());
|
return int.Parse(config[name].ToString());
|
||||||
else return -1;
|
else return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool isConfig(string name)
|
public static bool isConfig(string name)
|
||||||
@@ -83,11 +83,11 @@ public static class AppConfig
|
|||||||
return getConfig(name) == 1;
|
return getConfig(name) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string getConfigString(string name)
|
public static string getConfigString(string name, string empty = null)
|
||||||
{
|
{
|
||||||
if (config.ContainsKey(name))
|
if (config.ContainsKey(name))
|
||||||
return config[name].ToString();
|
return config[name].ToString();
|
||||||
else return null;
|
else return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setConfig(string name, int value)
|
public static void setConfig(string name, int value)
|
||||||
|
|||||||
@@ -248,23 +248,31 @@ namespace GHelper
|
|||||||
|
|
||||||
public static void ApplyBrightness(int brightness)
|
public static void ApplyBrightness(int brightness)
|
||||||
{
|
{
|
||||||
Task.Run(async () =>
|
if (AppConfig.ContainsModel("TUF"))
|
||||||
|
Program.acpi.TUFKeyboardBrightness(brightness);
|
||||||
|
|
||||||
|
byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
|
||||||
|
|
||||||
|
var devices = GetHidDevices(deviceIds);
|
||||||
|
foreach (HidDevice device in devices)
|
||||||
{
|
{
|
||||||
|
device.OpenDevice();
|
||||||
byte[] msg = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
|
device.WriteFeatureData(msg);
|
||||||
Logger.WriteLine("KB Backlight:" + BitConverter.ToString(msg));
|
Logger.WriteLine("KB Backlight:" + BitConverter.ToString(msg));
|
||||||
|
device.CloseDevice();
|
||||||
|
}
|
||||||
|
|
||||||
var devices = GetHidDevices(deviceIds, 0);
|
|
||||||
foreach (HidDevice device in devices)
|
|
||||||
{
|
|
||||||
device.OpenDevice();
|
|
||||||
device.WriteFeatureData(msg);
|
|
||||||
device.CloseDevice();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AppConfig.ContainsModel("TUF"))
|
// Backup payload for old models
|
||||||
Program.acpi.TUFKeyboardBrightness(brightness);
|
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
|
||||||
});
|
|
||||||
|
var devicesBackup = GetHidDevices(deviceIds, 0);
|
||||||
|
foreach (HidDevice device in devicesBackup)
|
||||||
|
{
|
||||||
|
device.OpenDevice();
|
||||||
|
device.WriteFeatureData(msgBackup);
|
||||||
|
device.CloseDevice();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -381,23 +389,6 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetBacklightOffDelay(int value = 60)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
RegistryKey myKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ASUS\ASUS System Control Interface\AsusOptimization\ASUS Keyboard Hotkeys", true);
|
|
||||||
if (myKey != null)
|
|
||||||
{
|
|
||||||
myKey.SetValue("TurnOffKeybdLight", value, RegistryValueKind.DWord);
|
|
||||||
myKey.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.WriteLine(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ namespace GHelper
|
|||||||
checkXMG.Checked = !(AppConfig.getConfig("xmg_light") == 0);
|
checkXMG.Checked = !(AppConfig.getConfig("xmg_light") == 0);
|
||||||
checkXMG.CheckedChanged += CheckXMG_CheckedChanged;
|
checkXMG.CheckedChanged += CheckXMG_CheckedChanged;
|
||||||
|
|
||||||
int kb_timeout = AppConfig.getConfig("keyboard_light_tiomeout");
|
int kb_timeout = AppConfig.getConfig("keyboard_timeout");
|
||||||
numericBacklightTime.Value = (kb_timeout >= 0) ? kb_timeout : 60;
|
numericBacklightTime.Value = (kb_timeout >= 0) ? kb_timeout : 60;
|
||||||
|
|
||||||
numericBacklightTime.ValueChanged += NumericBacklightTime_ValueChanged;
|
numericBacklightTime.ValueChanged += NumericBacklightTime_ValueChanged;
|
||||||
@@ -218,9 +218,7 @@ namespace GHelper
|
|||||||
|
|
||||||
private void NumericBacklightTime_ValueChanged(object? sender, EventArgs e)
|
private void NumericBacklightTime_ValueChanged(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Program.RunAsAdmin("extra");
|
AppConfig.setConfig("keyboard_timeout", (int)numericBacklightTime.Value);
|
||||||
AppConfig.setConfig("keyboard_light_tiomeout", (int)numericBacklightTime.Value);
|
|
||||||
AsusUSB.SetBacklightOffDelay((int)numericBacklightTime.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckXMG_CheckedChanged(object? sender, EventArgs e)
|
private void CheckXMG_CheckedChanged(object? sender, EventArgs e)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
<AssemblyVersion>0.68</AssemblyVersion>
|
<AssemblyVersion>0.69</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ namespace GHelper
|
|||||||
|
|
||||||
public class InputDispatcher
|
public class InputDispatcher
|
||||||
{
|
{
|
||||||
|
System.Timers.Timer timer = new System.Timers.Timer(1000);
|
||||||
|
public bool backlight = true;
|
||||||
|
|
||||||
private static nint windowHandle;
|
private static nint windowHandle;
|
||||||
|
|
||||||
@@ -84,15 +86,43 @@ namespace GHelper
|
|||||||
|
|
||||||
RegisterKeys();
|
RegisterKeys();
|
||||||
|
|
||||||
|
timer.Elapsed += Timer_Elapsed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitListener()
|
private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
TimeSpan iddle = NativeMethods.GetIdleTime();
|
||||||
|
int kb_timeout = AppConfig.getConfig("keyboard_timeout", 60);
|
||||||
|
|
||||||
|
if (kb_timeout == 0) return;
|
||||||
|
|
||||||
|
if (backlight && iddle.TotalSeconds > kb_timeout)
|
||||||
|
{
|
||||||
|
backlight = false;
|
||||||
|
AsusUSB.ApplyBrightness(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!backlight && iddle.TotalSeconds < kb_timeout)
|
||||||
|
{
|
||||||
|
backlight = true;
|
||||||
|
AsusUSB.ApplyBrightness(AppConfig.getConfig("keyboard_brightness"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Debug.WriteLine(iddle.TotalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
{
|
{
|
||||||
if (listener is not null) listener.Dispose();
|
if (listener is not null) listener.Dispose();
|
||||||
|
|
||||||
|
Program.acpi.DeviceInit();
|
||||||
|
|
||||||
if (!OptimizationService.IsRunning())
|
if (!OptimizationService.IsRunning())
|
||||||
listener = new KeyboardListener(HandleEvent);
|
listener = new KeyboardListener(HandleEvent);
|
||||||
|
|
||||||
|
timer.Enabled = (AppConfig.getConfig("keyboard_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
|
||||||
using static Tools.ScreenInterrogatory;
|
using static Tools.ScreenInterrogatory;
|
||||||
|
|
||||||
namespace Tools
|
namespace Tools
|
||||||
@@ -351,6 +352,25 @@ namespace Tools
|
|||||||
public class NativeMethods
|
public class NativeMethods
|
||||||
{
|
{
|
||||||
|
|
||||||
|
internal struct LASTINPUTINFO
|
||||||
|
{
|
||||||
|
public uint cbSize;
|
||||||
|
public uint dwTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("User32.dll")]
|
||||||
|
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
|
||||||
|
|
||||||
|
public static TimeSpan GetIdleTime()
|
||||||
|
{
|
||||||
|
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
|
||||||
|
lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut);
|
||||||
|
GetLastInputInfo(ref lastInPut);
|
||||||
|
return TimeSpan.FromMilliseconds((uint)Environment.TickCount - lastInPut.dwTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private const int WM_SYSCOMMAND = 0x0112;
|
private const int WM_SYSCOMMAND = 0x0112;
|
||||||
private const int SC_MONITORPOWER = 0xF170;
|
private const int SC_MONITORPOWER = 0xF170;
|
||||||
private const int MONITOR_OFF = 2;
|
private const int MONITOR_OFF = 2;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
@@ -40,6 +41,25 @@ namespace GHelper
|
|||||||
return (Process.GetProcessesByName("AsusOptimization").Count() > 0);
|
return (Process.GetProcessesByName("AsusOptimization").Count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void SetBacklightOffDelay(int value = 60)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RegistryKey myKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ASUS\ASUS System Control Interface\AsusOptimization\ASUS Keyboard Hotkeys", true);
|
||||||
|
if (myKey != null)
|
||||||
|
{
|
||||||
|
myKey.SetValue("TurnOffKeybdLight", value, RegistryValueKind.DWord);
|
||||||
|
myKey.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ namespace GHelper
|
|||||||
|
|
||||||
public static InputDispatcher inputDispatcher;
|
public static InputDispatcher inputDispatcher;
|
||||||
|
|
||||||
private static PowerLineStatus isPlugged = PowerLineStatus.Unknown;
|
private static PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
||||||
|
|
||||||
// The main entry point for the application
|
// The main entry point for the application
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
@@ -144,7 +144,7 @@ namespace GHelper
|
|||||||
isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
||||||
Logger.WriteLine("AutoSetting for " + isPlugged.ToString());
|
Logger.WriteLine("AutoSetting for " + isPlugged.ToString());
|
||||||
|
|
||||||
inputDispatcher.InitListener();
|
inputDispatcher.Init();
|
||||||
|
|
||||||
settingsForm.SetBatteryChargeLimit(AppConfig.getConfig("charge_limit"));
|
settingsForm.SetBatteryChargeLimit(AppConfig.getConfig("charge_limit"));
|
||||||
settingsForm.AutoPerformance();
|
settingsForm.AutoPerformance();
|
||||||
@@ -163,9 +163,10 @@ namespace GHelper
|
|||||||
|
|
||||||
private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
|
private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (SystemInformation.PowerStatus.PowerLineStatus == isPlugged) return;
|
if (SystemInformation.PowerStatus.PowerLineStatus == isPlugged) return;
|
||||||
|
|
||||||
Logger.WriteLine("Windows - Power Mode Changed");
|
Logger.WriteLine("Power Mode Changed");
|
||||||
SetAutoModes();
|
SetAutoModes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
102
app/Settings.cs
102
app/Settings.cs
@@ -153,6 +153,55 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void WndProc(ref Message m)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (m.Msg)
|
||||||
|
{
|
||||||
|
case NativeMethods.WM_POWERBROADCAST:
|
||||||
|
if (m.WParam == (IntPtr)NativeMethods.PBT_POWERSETTINGCHANGE)
|
||||||
|
{
|
||||||
|
var settings = (NativeMethods.POWERBROADCAST_SETTING)m.GetLParam(typeof(NativeMethods.POWERBROADCAST_SETTING));
|
||||||
|
switch (settings.Data)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Logger.WriteLine("Monitor Power Off");
|
||||||
|
AsusUSB.ApplyBrightness(0);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Logger.WriteLine("Monitor Power On");
|
||||||
|
Program.SetAutoModes();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Logger.WriteLine("Monitor Dimmed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Result = (IntPtr)1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KeyHandler.WM_HOTKEY_MSG_ID:
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
public void RunToast(string text, ToastIcon? icon = null)
|
public void RunToast(string text, ToastIcon? icon = null)
|
||||||
{
|
{
|
||||||
toast.RunToast(text, icon);
|
toast.RunToast(text, icon);
|
||||||
@@ -493,59 +542,6 @@ namespace GHelper
|
|||||||
AutoScreen();
|
AutoScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void WndProc(ref Message m)
|
|
||||||
{
|
|
||||||
|
|
||||||
switch (m.Msg)
|
|
||||||
{
|
|
||||||
case NativeMethods.WM_POWERBROADCAST:
|
|
||||||
if (m.WParam == (IntPtr)NativeMethods.PBT_POWERSETTINGCHANGE)
|
|
||||||
{
|
|
||||||
var settings = (NativeMethods.POWERBROADCAST_SETTING)m.GetLParam(typeof(NativeMethods.POWERBROADCAST_SETTING));
|
|
||||||
switch (settings.Data)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Logger.WriteLine("Monitor Power Off");
|
|
||||||
AsusUSB.ApplyBrightness(0);
|
|
||||||
SetBatteryChargeLimit(AppConfig.getConfig("charge_limit"));
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
Logger.WriteLine("Monitor Power On");
|
|
||||||
Program.SetAutoModes();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
Logger.WriteLine("Monitor Dimmed");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.Result = (IntPtr)1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KeyHandler.WM_HOTKEY_MSG_ID:
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void CheckStartup_CheckedChanged(object? sender, EventArgs e)
|
private void CheckStartup_CheckedChanged(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user