Compare commits

...

5 Commits
v0.74 ... v0.75

Author SHA1 Message Date
Serge
314d25c751 Backlight fix 2023-06-01 15:24:51 +02:00
Serge
b52163949c Auto brightness tweak 2023-06-01 15:18:41 +02:00
Serge
f0ee2b8aac Fn-lock support for optimization service 2023-06-01 14:32:29 +02:00
Serge
1603f625ed FN-Lock support for case when optimization service is running 2023-06-01 14:19:43 +02:00
Serge
8f66006791 Fn-lock tweaks 2023-06-01 12:52:35 +02:00
13 changed files with 136 additions and 41 deletions

View File

@@ -60,7 +60,7 @@ public static class AppConfig
{ {
GetModel(); GetModel();
return (_model is not null && _model.Contains(contains)); return (_model is not null && _model.ToLower().Contains(contains.ToLower()));
} }
private static void initConfig() private static void initConfig()

View File

@@ -83,6 +83,7 @@ public class AsusACPI
public const int TUF_KB_STATE = 0x00100057; public const int TUF_KB_STATE = 0x00100057;
public const int TabletState = 0x00060077; public const int TabletState = 0x00060077;
public const int FnLock = 0x00100023;
public const int Tablet_Notebook = 0; public const int Tablet_Notebook = 0;
public const int Tablet_Tablet = 1; public const int Tablet_Tablet = 1;

24
app/Extra.Designer.cs generated
View File

@@ -83,13 +83,13 @@ namespace GHelper
checkSleepLid = new CheckBox(); checkSleepLid = new CheckBox();
checkShutdownLid = new CheckBox(); checkShutdownLid = new CheckBox();
groupOther = new GroupBox(); groupOther = new GroupBox();
checkFnLock = new CheckBox();
checkGpuApps = new CheckBox(); checkGpuApps = new CheckBox();
checkAutoApplyWindowsPowerMode = new CheckBox(); checkAutoApplyWindowsPowerMode = new CheckBox();
checkKeyboardAuto = new CheckBox(); checkKeyboardAuto = new CheckBox();
checkUSBC = new CheckBox(); checkUSBC = new CheckBox();
checkNoOverdrive = new CheckBox(); checkNoOverdrive = new CheckBox();
checkTopmost = new CheckBox(); checkTopmost = new CheckBox();
checkFnLock = new CheckBox();
groupBindings.SuspendLayout(); groupBindings.SuspendLayout();
tableKeys.SuspendLayout(); tableKeys.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit();
@@ -700,6 +700,17 @@ namespace GHelper
groupOther.TabStop = false; groupOther.TabStop = false;
groupOther.Text = "Other"; groupOther.Text = "Other";
// //
// checkFnLock
//
checkFnLock.AutoSize = true;
checkFnLock.Location = new Point(25, 89);
checkFnLock.MaximumSize = new Size(780, 0);
checkFnLock.Name = "checkFnLock";
checkFnLock.Size = new Size(397, 36);
checkFnLock.TabIndex = 49;
checkFnLock.Text = "Process Fn+F hotkeys without Fn";
checkFnLock.UseVisualStyleBackColor = true;
//
// checkGpuApps // checkGpuApps
// //
checkGpuApps.AutoSize = true; checkGpuApps.AutoSize = true;
@@ -761,17 +772,6 @@ namespace GHelper
checkTopmost.Text = Strings.WindowTop; checkTopmost.Text = Strings.WindowTop;
checkTopmost.UseVisualStyleBackColor = true; checkTopmost.UseVisualStyleBackColor = true;
// //
// checkFnLock
//
checkFnLock.AutoSize = true;
checkFnLock.Location = new Point(25, 89);
checkFnLock.MaximumSize = new Size(780, 0);
checkFnLock.Name = "checkFnLock";
checkFnLock.Size = new Size(401, 36);
checkFnLock.TabIndex = 49;
checkFnLock.Text = "Process Fn+F hotkeys without FN";
checkFnLock.UseVisualStyleBackColor = true;
//
// Extra // Extra
// //
AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleDimensions = new SizeF(13F, 32F);

View File

@@ -1,4 +1,5 @@
using CustomControls; using CustomControls;
using Microsoft.VisualBasic.Devices;
using System.Diagnostics; using System.Diagnostics;
namespace GHelper namespace GHelper
@@ -93,6 +94,7 @@ namespace GHelper
checkTopmost.Text = Properties.Strings.WindowTop; checkTopmost.Text = Properties.Strings.WindowTop;
checkUSBC.Text = Properties.Strings.OptimizedUSBC; checkUSBC.Text = Properties.Strings.OptimizedUSBC;
checkAutoApplyWindowsPowerMode.Text = Properties.Strings.ApplyWindowsPowerPlan; checkAutoApplyWindowsPowerMode.Text = Properties.Strings.ApplyWindowsPowerPlan;
checkFnLock.Text = Properties.Strings.FnLock;
labelBacklight.Text = Properties.Strings.Keyboard; labelBacklight.Text = Properties.Strings.Keyboard;
labelBacklightBar.Text = Properties.Strings.Lightbar; labelBacklightBar.Text = Properties.Strings.Lightbar;
@@ -228,7 +230,10 @@ namespace GHelper
private void CheckFnLock_CheckedChanged(object? sender, EventArgs e) private void CheckFnLock_CheckedChanged(object? sender, EventArgs e)
{ {
AppConfig.setConfig("fn_lock", (checkFnLock.Checked ? 1 : 0)); int fnLock = checkFnLock.Checked ? 1 : 0;
AppConfig.setConfig("fn_lock", fnLock);
Program.acpi.DeviceSet(AsusACPI.FnLock, (fnLock == 1) ? 0 : 1, "FnLock");
Program.inputDispatcher.RegisterKeys(); Program.inputDispatcher.RegisterKeys();
} }

View File

@@ -16,7 +16,7 @@
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.74</AssemblyVersion> <AssemblyVersion>0.75</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -19,9 +19,12 @@ public static class HardwareControl
public static int GetFanMax() public static int GetFanMax()
{ {
int max = 58; int max = 58;
int configMax = AppConfig.getConfig("fan_max");
if (configMax > 100) configMax = 0; // skipping inadvequate settings
if (AppConfig.ContainsModel("401")) max = 72; if (AppConfig.ContainsModel("401")) max = 72;
else if (AppConfig.ContainsModel("503")) max = 68; else if (AppConfig.ContainsModel("503")) max = 68;
return Math.Max(max, AppConfig.getConfig("fan_max")); return Math.Max(max, configMax);
} }
public static void SetFanMax(int fan) public static void SetFanMax(int fan)

View File

@@ -128,6 +128,8 @@ namespace GHelper
public void RegisterKeys() public void RegisterKeys()
{ {
hook.UnregisterAll();
// CTRL + SHIFT + F5 to cycle profiles // CTRL + SHIFT + F5 to cycle profiles
if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile"); if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile");
if (AppConfig.getConfig("keybind_app") != -1) keyApp = (Keys)AppConfig.getConfig("keybind_app"); if (AppConfig.getConfig("keybind_app") != -1) keyApp = (Keys)AppConfig.getConfig("keybind_app");
@@ -135,18 +137,17 @@ namespace GHelper
string actionM1 = AppConfig.getConfigString("m1"); string actionM1 = AppConfig.getConfigString("m1");
string actionM2 = AppConfig.getConfigString("m2"); string actionM2 = AppConfig.getConfigString("m2");
hook.UnregisterAll();
if (keyProfile != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyProfile); if (keyProfile != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyProfile);
if (keyApp != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyApp); if (keyApp != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyApp);
if (actionM1 is not null && actionM1.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeDown); if (!AppConfig.ContainsModel("Z13"))
if (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp); if (actionM1 is not null && actionM1.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeDown);
if (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp);
// FN-Lock group // FN-Lock group
if (AppConfig.isConfig("fn_lock")) if (AppConfig.isConfig("fn_lock") && !AppConfig.ContainsModel("VivoBook"))
for (Keys i = Keys.F1; i < Keys.F12; i++) hook.RegisterHotKey(ModifierKeys.None, i); for (Keys i = Keys.F1; i <= Keys.F11; i++) hook.RegisterHotKey(ModifierKeys.None, i);
} }
@@ -177,17 +178,38 @@ namespace GHelper
if (e.Modifier == ModifierKeys.None) if (e.Modifier == ModifierKeys.None)
{ {
Debug.WriteLine(e.Key); Logger.WriteLine(e.Key.ToString());
if (AppConfig.ContainsModel("Z13"))
{
switch (e.Key)
{
case Keys.F2:
KeyboardHook.KeyPress(Keys.VolumeDown);
return;
case Keys.F3:
KeyboardHook.KeyPress(Keys.VolumeUp);
return;
case Keys.F4:
KeyProcess("m3");
return;
case Keys.F11:
OptimizationEvent(199);
return;
}
}
switch (e.Key) switch (e.Key)
{ {
case Keys.F1: case Keys.F1:
KeyboardHook.KeyPress(Keys.VolumeMute); KeyboardHook.KeyPress(Keys.VolumeMute);
break; break;
case Keys.F2: case Keys.F2:
HandleEvent(197); OptimizationEvent(197);
break; break;
case Keys.F3: case Keys.F3:
HandleEvent(196); OptimizationEvent(196);
break; break;
case Keys.F4: case Keys.F4:
KeyProcess("fnf4"); KeyProcess("fnf4");
@@ -199,20 +221,26 @@ namespace GHelper
KeyboardHook.KeyPress(Keys.Snapshot); KeyboardHook.KeyPress(Keys.Snapshot);
break; break;
case Keys.F7: case Keys.F7:
HandleEvent(16); if (AppConfig.ContainsModel("TUF"))
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(-10) + "%", ToastIcon.BrightnessDown);
OptimizationEvent(16);
break; break;
case Keys.F8: case Keys.F8:
HandleEvent(32); if (AppConfig.ContainsModel("TUF"))
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(+10) + "%", ToastIcon.BrightnessUp);
OptimizationEvent(32);
break; break;
case Keys.F9: case Keys.F9:
KeyboardHook.KeyWinPress(Keys.P);
break; break;
case Keys.F10: case Keys.F10:
HandleEvent(107); OptimizationEvent(107);
break; break;
case Keys.F11: case Keys.F11:
HandleEvent(108); OptimizationEvent(108);
break; break;
case Keys.F12: case Keys.F12:
KeyboardHook.KeyWinPress(Keys.A);
break; break;
case Keys.VolumeDown: case Keys.VolumeDown:
KeyProcess("m1"); KeyProcess("m1");
@@ -306,6 +334,13 @@ namespace GHelper
} }
} }
static void ToggleFnLock()
{
int fnLock = AppConfig.isConfig("fn_lock") ? 0 : 1;
AppConfig.setConfig("fn_lock", fnLock);
Program.acpi.DeviceSet(AsusACPI.FnLock, (fnLock == 1) ? 0 : 1, "FnLock");
}
static void TabletMode() static void TabletMode()
{ {
bool touchpadState = GetTouchpadState(); bool touchpadState = GetTouchpadState();
@@ -337,9 +372,16 @@ namespace GHelper
case 189: // Tablet mode case 189: // Tablet mode
TabletMode(); TabletMode();
return; return;
case 78: // Fn + ESC
ToggleFnLock();
return;
} }
if (OptimizationService.IsRunning()) return; if (!OptimizationService.IsRunning()) OptimizationEvent(EventID);
}
static void OptimizationEvent(int EventID)
{
// Asus Optimization service Events // Asus Optimization service Events

View File

@@ -1,5 +1,4 @@
using System.Diagnostics; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
public sealed class KeyboardHook : IDisposable public sealed class KeyboardHook : IDisposable
{ {
@@ -18,12 +17,22 @@ public sealed class KeyboardHook : IDisposable
public const int KEYEVENTF_EXTENDEDKEY = 1; public const int KEYEVENTF_EXTENDEDKEY = 1;
public const int KEYEVENTF_KEYUP = 2; public const int KEYEVENTF_KEYUP = 2;
private const byte VK_LWIN = 0x5B;
public static void KeyPress(Keys key) public static void KeyPress(Keys key)
{ {
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
} }
public static void KeyWinPress(Keys key)
{
keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
}
/// <summary> /// <summary>
/// Represents the window that is used internally to get the messages. /// Represents the window that is used internally to get the messages.
/// </summary> /// </summary>
@@ -96,7 +105,7 @@ public sealed class KeyboardHook : IDisposable
// register the hot key. // register the hot key.
if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key)) if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
throw new InvalidOperationException("Couldnt register the hot key."); Logger.WriteLine("Couldnt register " + key);
} }
/// <summary> /// <summary>

View File

@@ -702,6 +702,8 @@ public class NativeMethods
{ {
Guid activeSchemeGuid = GetActiveScheme(); Guid activeSchemeGuid = GetActiveScheme();
if (boost == GetCPUBoost()) return;
var hrAC = PowerWriteACValueIndex( var hrAC = PowerWriteACValueIndex(
IntPtr.Zero, IntPtr.Zero,
activeSchemeGuid, activeSchemeGuid,

View File

@@ -510,6 +510,15 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Process Fn+F hotkeys without Fn.
/// </summary>
internal static string FnLock {
get {
return ResourceManager.GetString("FnLock", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Dynamic Boost. /// Looks up a localized string similar to Dynamic Boost.
/// </summary> /// </summary>

View File

@@ -267,6 +267,9 @@
<data name="FansPower" xml:space="preserve"> <data name="FansPower" xml:space="preserve">
<value>Fans + Power</value> <value>Fans + Power</value>
</data> </data>
<data name="FnLock" xml:space="preserve">
<value>Process Fn+F hotkeys without Fn</value>
</data>
<data name="GPUBoost" xml:space="preserve"> <data name="GPUBoost" xml:space="preserve">
<value>Dynamic Boost</value> <value>Dynamic Boost</value>
</data> </data>

View File

@@ -189,6 +189,12 @@
<data name="Awake" xml:space="preserve"> <data name="Awake" xml:space="preserve">
<value>唤醒时</value> <value>唤醒时</value>
</data> </data>
<data name="BacklightTimeout" xml:space="preserve">
<value>使用电池时的背光超时时间</value>
</data>
<data name="BacklightTimeoutPlugged" xml:space="preserve">
<value>插入电源时的背光超时时间 (0 - 始终开启)</value>
</data>
<data name="Balanced" xml:space="preserve"> <data name="Balanced" xml:space="preserve">
<value>平衡模式</value> <value>平衡模式</value>
</data> </data>
@@ -258,6 +264,9 @@
<data name="FansPower" xml:space="preserve"> <data name="FansPower" xml:space="preserve">
<value>风扇与电源设置</value> <value>风扇与电源设置</value>
</data> </data>
<data name="FnLock" xml:space="preserve">
<value>无需FN处理 Fn+F 热键</value>
</data>
<data name="GPUChanging" xml:space="preserve"> <data name="GPUChanging" xml:space="preserve">
<value>切换中...</value> <value>切换中...</value>
</data> </data>
@@ -282,6 +291,9 @@
<data name="KeyboardAuto" xml:space="preserve"> <data name="KeyboardAuto" xml:space="preserve">
<value>电池模式下降低键盘亮度以省电,并在插上电源时恢复</value> <value>电池模式下降低键盘亮度以省电,并在插上电源时恢复</value>
</data> </data>
<data name="KillGpuApps" xml:space="preserve">
<value>当切换到集显模式时停止所有正在使用dGPU的应用</value>
</data>
<data name="LaptopBacklight" xml:space="preserve"> <data name="LaptopBacklight" xml:space="preserve">
<value>背光</value> <value>背光</value>
</data> </data>
@@ -324,6 +336,9 @@
<data name="Multizone" xml:space="preserve"> <data name="Multizone" xml:space="preserve">
<value>多区域设置</value> <value>多区域设置</value>
</data> </data>
<data name="MuteMic" xml:space="preserve">
<value>静音麦克风</value>
</data>
<data name="OpenGHelper" xml:space="preserve"> <data name="OpenGHelper" xml:space="preserve">
<value>打开G-Helper窗口</value> <value>打开G-Helper窗口</value>
</data> </data>
@@ -333,6 +348,9 @@
<data name="OptimizedGPUTooltip" xml:space="preserve"> <data name="OptimizedGPUTooltip" xml:space="preserve">
<value>使用电池时切换到集显模式,并在插上电源后重新启用标准模式</value> <value>使用电池时切换到集显模式,并在插上电源后重新启用标准模式</value>
</data> </data>
<data name="OptimizedUSBC" xml:space="preserve">
<value>在自动切换模式下使用USB-C充电器时禁用GPU</value>
</data>
<data name="Other" xml:space="preserve"> <data name="Other" xml:space="preserve">
<value>其他</value> <value>其他</value>
</data> </data>
@@ -405,9 +423,15 @@
<data name="VersionLabel" xml:space="preserve"> <data name="VersionLabel" xml:space="preserve">
<value>版本</value> <value>版本</value>
</data> </data>
<data name="VolumeDown" xml:space="preserve">
<value>音量降低</value>
</data>
<data name="VolumeMute" xml:space="preserve"> <data name="VolumeMute" xml:space="preserve">
<value>静音</value> <value>静音</value>
</data> </data>
<data name="VolumeUp" xml:space="preserve">
<value>音量增加</value>
</data>
<data name="WindowTop" xml:space="preserve"> <data name="WindowTop" xml:space="preserve">
<value>窗口置顶</value> <value>窗口置顶</value>
</data> </data>

View File

@@ -1282,13 +1282,10 @@ namespace GHelper
int backlight = AppConfig.getConfig("keyboard_brightness"); int backlight = AppConfig.getConfig("keyboard_brightness");
if (backlight > 0) if (AppConfig.isConfig("keyboard_auto") && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)
{ AsusUSB.ApplyBrightness(0);
if (AppConfig.isConfig("keyboard_auto") && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online) else
AsusUSB.ApplyBrightness(1); AsusUSB.ApplyBrightness(backlight);
else
AsusUSB.ApplyBrightness(backlight);
}
} }