Fn-lock tweaks

This commit is contained in:
Serge
2023-06-01 12:52:35 +02:00
parent 39387041fe
commit 8f66006791
10 changed files with 116 additions and 23 deletions

View File

@@ -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()

View File

@@ -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;

24
app/Extra.Designer.cs generated
View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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)

View File

@@ -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;

View File

@@ -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);
}
/// <summary>
/// Represents the window that is used internally to get the messages.
/// </summary>

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>
/// Looks up a localized string similar to Dynamic Boost.
/// </summary>

View File

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

View File

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