From 8f66006791e5637a6a0872f6f2635b0ef85182c3 Mon Sep 17 00:00:00 2001
From: Serge <5920850+seerge@users.noreply.github.com>
Date: Thu, 1 Jun 2023 12:52:35 +0200
Subject: [PATCH] Fn-lock tweaks
---
app/AppConfig.cs | 2 +-
app/AsusACPI.cs | 1 +
app/Extra.Designer.cs | 24 +++++++--------
app/Extra.cs | 7 ++++-
app/HardwareControl.cs | 5 ++-
app/InputDispatcher.cs | 49 +++++++++++++++++++++++++++---
app/KeyboardHook.cs | 13 ++++++--
app/Properties/Strings.Designer.cs | 9 ++++++
app/Properties/Strings.resx | 3 ++
app/Properties/Strings.zh-CN.resx | 26 +++++++++++++++-
10 files changed, 116 insertions(+), 23 deletions(-)
diff --git a/app/AppConfig.cs b/app/AppConfig.cs
index c6f64cc9..e1ec8234 100644
--- a/app/AppConfig.cs
+++ b/app/AppConfig.cs
@@ -60,7 +60,7 @@ public static class AppConfig
{
GetModel();
- return (_model is not null && _model.Contains(contains));
+ return (_model is not null && _model.ToLower().Contains(contains.ToLower()));
}
private static void initConfig()
diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs
index 730b87c4..e5ff9a84 100644
--- a/app/AsusACPI.cs
+++ b/app/AsusACPI.cs
@@ -83,6 +83,7 @@ public class AsusACPI
public const int TUF_KB_STATE = 0x00100057;
public const int TabletState = 0x00060077;
+ public const int FnLock = 0x00100023;
public const int Tablet_Notebook = 0;
public const int Tablet_Tablet = 1;
diff --git a/app/Extra.Designer.cs b/app/Extra.Designer.cs
index f9dcd687..f2beec71 100644
--- a/app/Extra.Designer.cs
+++ b/app/Extra.Designer.cs
@@ -83,13 +83,13 @@ namespace GHelper
checkSleepLid = new CheckBox();
checkShutdownLid = new CheckBox();
groupOther = new GroupBox();
+ checkFnLock = new CheckBox();
checkGpuApps = new CheckBox();
checkAutoApplyWindowsPowerMode = new CheckBox();
checkKeyboardAuto = new CheckBox();
checkUSBC = new CheckBox();
checkNoOverdrive = new CheckBox();
checkTopmost = new CheckBox();
- checkFnLock = new CheckBox();
groupBindings.SuspendLayout();
tableKeys.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit();
@@ -700,6 +700,17 @@ namespace GHelper
groupOther.TabStop = false;
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.AutoSize = true;
@@ -761,17 +772,6 @@ namespace GHelper
checkTopmost.Text = Strings.WindowTop;
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
//
AutoScaleDimensions = new SizeF(13F, 32F);
diff --git a/app/Extra.cs b/app/Extra.cs
index 7c3f0ae1..91655d70 100644
--- a/app/Extra.cs
+++ b/app/Extra.cs
@@ -1,4 +1,5 @@
using CustomControls;
+using Microsoft.VisualBasic.Devices;
using System.Diagnostics;
namespace GHelper
@@ -93,6 +94,7 @@ namespace GHelper
checkTopmost.Text = Properties.Strings.WindowTop;
checkUSBC.Text = Properties.Strings.OptimizedUSBC;
checkAutoApplyWindowsPowerMode.Text = Properties.Strings.ApplyWindowsPowerPlan;
+ checkFnLock.Text = Properties.Strings.FnLock;
labelBacklight.Text = Properties.Strings.Keyboard;
labelBacklightBar.Text = Properties.Strings.Lightbar;
@@ -228,7 +230,10 @@ namespace GHelper
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();
}
diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs
index d4b79cda..85b27149 100644
--- a/app/HardwareControl.cs
+++ b/app/HardwareControl.cs
@@ -19,9 +19,12 @@ public static class HardwareControl
public static int GetFanMax()
{
int max = 58;
+ int configMax = AppConfig.getConfig("fan_max");
+ if (configMax > 100) configMax = 0; // skipping inadvequate settings
+
if (AppConfig.ContainsModel("401")) max = 72;
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)
diff --git a/app/InputDispatcher.cs b/app/InputDispatcher.cs
index 22016330..28f7319a 100644
--- a/app/InputDispatcher.cs
+++ b/app/InputDispatcher.cs
@@ -128,6 +128,8 @@ namespace GHelper
public void RegisterKeys()
{
+ hook.UnregisterAll();
+
// CTRL + SHIFT + F5 to cycle profiles
if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile");
if (AppConfig.getConfig("keybind_app") != -1) keyApp = (Keys)AppConfig.getConfig("keybind_app");
@@ -135,17 +137,17 @@ namespace GHelper
string actionM1 = AppConfig.getConfigString("m1");
string actionM2 = AppConfig.getConfigString("m2");
- hook.UnregisterAll();
if (keyProfile != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyProfile);
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 (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp);
+ if (!AppConfig.ContainsModel("Z13"))
+ 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
- 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);
}
@@ -177,7 +179,28 @@ namespace GHelper
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:
+ HandleEvent(199);
+ return;
+ }
+ }
+
+
switch (e.Key)
{
case Keys.F1:
@@ -199,12 +222,17 @@ namespace GHelper
KeyboardHook.KeyPress(Keys.Snapshot);
break;
case Keys.F7:
+ if (AppConfig.ContainsModel("TUF"))
+ Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(-10) + "%", ToastIcon.BrightnessDown);
HandleEvent(16);
break;
case Keys.F8:
+ if (AppConfig.ContainsModel("TUF"))
+ Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(+10) + "%", ToastIcon.BrightnessUp);
HandleEvent(32);
break;
case Keys.F9:
+ KeyboardHook.KeyWinPress(Keys.P);
break;
case Keys.F10:
HandleEvent(107);
@@ -213,6 +241,7 @@ namespace GHelper
HandleEvent(108);
break;
case Keys.F12:
+ KeyboardHook.KeyWinPress(Keys.A);
break;
case Keys.VolumeDown:
KeyProcess("m1");
@@ -306,6 +335,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()
{
bool touchpadState = GetTouchpadState();
@@ -337,6 +373,9 @@ namespace GHelper
case 189: // Tablet mode
TabletMode();
return;
+ case 78: // Fn + ESC
+ ToggleFnLock();
+ return;
}
if (OptimizationService.IsRunning()) return;
diff --git a/app/KeyboardHook.cs b/app/KeyboardHook.cs
index 4d97e8f9..1c60230f 100644
--- a/app/KeyboardHook.cs
+++ b/app/KeyboardHook.cs
@@ -1,5 +1,4 @@
-using System.Diagnostics;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
public sealed class KeyboardHook : IDisposable
{
@@ -18,12 +17,22 @@ public sealed class KeyboardHook : IDisposable
public const int KEYEVENTF_EXTENDEDKEY = 1;
public const int KEYEVENTF_KEYUP = 2;
+ private const byte VK_LWIN = 0x5B;
public static void KeyPress(Keys key)
{
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);
+ }
+
+
///
/// Represents the window that is used internally to get the messages.
///
diff --git a/app/Properties/Strings.Designer.cs b/app/Properties/Strings.Designer.cs
index 0a5125c4..fcf86b27 100644
--- a/app/Properties/Strings.Designer.cs
+++ b/app/Properties/Strings.Designer.cs
@@ -510,6 +510,15 @@ namespace GHelper.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Process Fn+F hotkeys without Fn.
+ ///
+ internal static string FnLock {
+ get {
+ return ResourceManager.GetString("FnLock", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Dynamic Boost.
///
diff --git a/app/Properties/Strings.resx b/app/Properties/Strings.resx
index 063d5d3e..9d3582ec 100644
--- a/app/Properties/Strings.resx
+++ b/app/Properties/Strings.resx
@@ -267,6 +267,9 @@
Fans + Power
+
+ Process Fn+F hotkeys without Fn
+
Dynamic Boost
diff --git a/app/Properties/Strings.zh-CN.resx b/app/Properties/Strings.zh-CN.resx
index 7b37a6ba..dedb3de0 100644
--- a/app/Properties/Strings.zh-CN.resx
+++ b/app/Properties/Strings.zh-CN.resx
@@ -189,6 +189,12 @@
唤醒时
+
+ 使用电池时的背光超时时间
+
+
+ 插入电源时的背光超时时间 (0 - 始终开启)
+
平衡模式
@@ -258,6 +264,9 @@
风扇与电源设置
+
+ 无需FN处理 Fn+F 热键
+
切换中...
@@ -282,6 +291,9 @@
电池模式下降低键盘亮度以省电,并在插上电源时恢复
+
+ 当切换到集显模式时,停止所有正在使用dGPU的应用
+
背光
@@ -324,6 +336,9 @@
多区域设置
+
+ 静音麦克风
+
打开G-Helper窗口
@@ -333,6 +348,9 @@
使用电池时切换到集显模式,并在插上电源后重新启用标准模式
+
+ 在自动切换模式下,使用USB-C充电器时禁用GPU
+
其他
@@ -405,10 +423,16 @@
版本
+
+ 音量降低
+
静音
+
+ 音量增加
+
窗口置顶
-
+
\ No newline at end of file