Compare commits

...

6 Commits
v0.73 ... v0.74

Author SHA1 Message Date
Serge
39387041fe UI fixes 2023-05-31 17:41:24 +02:00
Serge
400b2cd6cb FN-lock 2023-05-31 17:33:53 +02:00
Serge
b20442e61f Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-31 17:23:54 +02:00
Serge
6d219511fc FN-Lock preparations 2023-05-31 17:23:52 +02:00
Serge
2282820453 Merge pull request #491 from marcelomijas/main
Spanish translation small fix
2023-05-31 11:51:11 +02:00
Marcelo Moreno
d4fcfe8895 Spanish translation small fix
Added translations for keyboard backlight timeout but they were too large... This is a shorter translation.
2023-05-31 11:36:13 +02:00
12 changed files with 336 additions and 165 deletions

30
app/Extra.Designer.cs generated
View File

@@ -89,6 +89,7 @@ namespace GHelper
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();
@@ -684,6 +685,7 @@ namespace GHelper
// //
// groupOther // groupOther
// //
groupOther.Controls.Add(checkFnLock);
groupOther.Controls.Add(checkGpuApps); groupOther.Controls.Add(checkGpuApps);
groupOther.Controls.Add(checkAutoApplyWindowsPowerMode); groupOther.Controls.Add(checkAutoApplyWindowsPowerMode);
groupOther.Controls.Add(checkKeyboardAuto); groupOther.Controls.Add(checkKeyboardAuto);
@@ -693,7 +695,7 @@ namespace GHelper
groupOther.Dock = DockStyle.Top; groupOther.Dock = DockStyle.Top;
groupOther.Location = new Point(10, 897); groupOther.Location = new Point(10, 897);
groupOther.Name = "groupOther"; groupOther.Name = "groupOther";
groupOther.Size = new Size(954, 310); groupOther.Size = new Size(954, 352);
groupOther.TabIndex = 2; groupOther.TabIndex = 2;
groupOther.TabStop = false; groupOther.TabStop = false;
groupOther.Text = "Other"; groupOther.Text = "Other";
@@ -701,7 +703,7 @@ namespace GHelper
// checkGpuApps // checkGpuApps
// //
checkGpuApps.AutoSize = true; checkGpuApps.AutoSize = true;
checkGpuApps.Location = new Point(25, 220); checkGpuApps.Location = new Point(25, 128);
checkGpuApps.Name = "checkGpuApps"; checkGpuApps.Name = "checkGpuApps";
checkGpuApps.Size = new Size(544, 36); checkGpuApps.Size = new Size(544, 36);
checkGpuApps.TabIndex = 48; checkGpuApps.TabIndex = 48;
@@ -711,7 +713,7 @@ namespace GHelper
// checkAutoApplyWindowsPowerMode // checkAutoApplyWindowsPowerMode
// //
checkAutoApplyWindowsPowerMode.AutoSize = true; checkAutoApplyWindowsPowerMode.AutoSize = true;
checkAutoApplyWindowsPowerMode.Location = new Point(25, 268); checkAutoApplyWindowsPowerMode.Location = new Point(25, 296);
checkAutoApplyWindowsPowerMode.Name = "checkAutoApplyWindowsPowerMode"; checkAutoApplyWindowsPowerMode.Name = "checkAutoApplyWindowsPowerMode";
checkAutoApplyWindowsPowerMode.Size = new Size(416, 36); checkAutoApplyWindowsPowerMode.Size = new Size(416, 36);
checkAutoApplyWindowsPowerMode.TabIndex = 47; checkAutoApplyWindowsPowerMode.TabIndex = 47;
@@ -721,7 +723,7 @@ namespace GHelper
// checkKeyboardAuto // checkKeyboardAuto
// //
checkKeyboardAuto.AutoSize = true; checkKeyboardAuto.AutoSize = true;
checkKeyboardAuto.Location = new Point(25, 40); checkKeyboardAuto.Location = new Point(25, 50);
checkKeyboardAuto.MaximumSize = new Size(780, 0); checkKeyboardAuto.MaximumSize = new Size(780, 0);
checkKeyboardAuto.Name = "checkKeyboardAuto"; checkKeyboardAuto.Name = "checkKeyboardAuto";
checkKeyboardAuto.Size = new Size(712, 36); checkKeyboardAuto.Size = new Size(712, 36);
@@ -732,7 +734,7 @@ namespace GHelper
// checkUSBC // checkUSBC
// //
checkUSBC.AutoSize = true; checkUSBC.AutoSize = true;
checkUSBC.Location = new Point(25, 85); checkUSBC.Location = new Point(25, 170);
checkUSBC.Name = "checkUSBC"; checkUSBC.Name = "checkUSBC";
checkUSBC.Size = new Size(659, 36); checkUSBC.Size = new Size(659, 36);
checkUSBC.TabIndex = 4; checkUSBC.TabIndex = 4;
@@ -742,7 +744,7 @@ namespace GHelper
// checkNoOverdrive // checkNoOverdrive
// //
checkNoOverdrive.AutoSize = true; checkNoOverdrive.AutoSize = true;
checkNoOverdrive.Location = new Point(25, 130); checkNoOverdrive.Location = new Point(25, 212);
checkNoOverdrive.Name = "checkNoOverdrive"; checkNoOverdrive.Name = "checkNoOverdrive";
checkNoOverdrive.Size = new Size(307, 36); checkNoOverdrive.Size = new Size(307, 36);
checkNoOverdrive.TabIndex = 3; checkNoOverdrive.TabIndex = 3;
@@ -752,20 +754,31 @@ namespace GHelper
// checkTopmost // checkTopmost
// //
checkTopmost.AutoSize = true; checkTopmost.AutoSize = true;
checkTopmost.Location = new Point(25, 175); checkTopmost.Location = new Point(25, 254);
checkTopmost.Name = "checkTopmost"; checkTopmost.Name = "checkTopmost";
checkTopmost.Size = new Size(390, 36); checkTopmost.Size = new Size(390, 36);
checkTopmost.TabIndex = 1; checkTopmost.TabIndex = 1;
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);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
AutoSize = true; AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink; AutoSizeMode = AutoSizeMode.GrowAndShrink;
ClientSize = new Size(974, 1220); ClientSize = new Size(974, 1262);
Controls.Add(groupOther); Controls.Add(groupOther);
Controls.Add(groupLight); Controls.Add(groupLight);
Controls.Add(groupBindings); Controls.Add(groupBindings);
@@ -859,5 +872,6 @@ namespace GHelper
private NumericUpDown numericBacklightPluggedTime; private NumericUpDown numericBacklightPluggedTime;
private Label labelBacklightTimeoutPlugged; private Label labelBacklightTimeoutPlugged;
private CheckBox checkGpuApps; private CheckBox checkGpuApps;
private CheckBox checkFnLock;
} }
} }

View File

@@ -222,6 +222,14 @@ namespace GHelper
checkGpuApps.Checked = AppConfig.isConfig("kill_gpu_apps"); checkGpuApps.Checked = AppConfig.isConfig("kill_gpu_apps");
checkGpuApps.CheckedChanged += CheckGpuApps_CheckedChanged; checkGpuApps.CheckedChanged += CheckGpuApps_CheckedChanged;
checkFnLock.Checked = AppConfig.isConfig("fn_lock");
checkFnLock.CheckedChanged += CheckFnLock_CheckedChanged; ;
}
private void CheckFnLock_CheckedChanged(object? sender, EventArgs e)
{
AppConfig.setConfig("fn_lock", (checkFnLock.Checked ? 1 : 0));
Program.inputDispatcher.RegisterKeys();
} }
private void CheckGpuApps_CheckedChanged(object? sender, EventArgs e) private void CheckGpuApps_CheckedChanged(object? sender, EventArgs e)

View File

@@ -417,7 +417,6 @@ namespace GHelper
powerVisible = panelPower.Visible = modeA0; powerVisible = panelPower.Visible = modeA0;
panelB0.Visible = modeB0; panelB0.Visible = modeB0;
panelC1.Visible = modeC1;
// All AMD version has B0 but doesn't have C0 (Nvidia GPU) settings // All AMD version has B0 but doesn't have C0 (Nvidia GPU) settings
@@ -431,6 +430,7 @@ namespace GHelper
{ {
labelLeftA0.Text = "CPU Slow (SPL + sPPT)"; labelLeftA0.Text = "CPU Slow (SPL + sPPT)";
labelLeftC1.Text = "CPU Fast (fPPT)"; labelLeftC1.Text = "CPU Fast (fPPT)";
panelC1.Visible = modeC1;
} }
int limit_total; int limit_total;

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.73</AssemblyVersion> <AssemblyVersion>0.74</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -1,13 +1,9 @@
using NvAPIWrapper; using NvAPIWrapper.GPU;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Native; using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Delegates;
using NvAPIWrapper.Native.GPU; using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures; using NvAPIWrapper.Native.GPU.Structures;
using NvAPIWrapper.Native.Interfaces.GPU; using NvAPIWrapper.Native.Interfaces.GPU;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Management;
using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1; using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1;
namespace GHelper.Gpu; namespace GHelper.Gpu;
@@ -58,7 +54,7 @@ public class NvidiaGpuControl : IGpuControl
try try
{ {
Process[] processes = internalGpu.GetActiveApplications(); Process[] processes = internalGpu.GetActiveApplications();
foreach (Process process in processes) foreach (Process process in processes)
{ {
try try
@@ -98,10 +94,11 @@ public class NvidiaGpuControl : IGpuControl
Logger.WriteLine($"GET GPU CLOCKS: {core}, {memory}"); Logger.WriteLine($"GET GPU CLOCKS: {core}, {memory}");
return 0; return 0;
} catch (Exception ex) }
catch (Exception ex)
{ {
Logger.WriteLine("GET GPU CLOCKS:" + ex.Message); Logger.WriteLine("GET GPU CLOCKS:" + ex.Message);
core = memory = 0; core = memory = 0;
return -1; return -1;
} }
@@ -155,7 +152,7 @@ public class NvidiaGpuControl : IGpuControl
//Thread.Sleep(2000); //Thread.Sleep(2000);
return true; return true;
} }
catch (Exception ex ) catch (Exception ex)
{ {
Logger.WriteLine(ex.ToString()); Logger.WriteLine(ex.ToString());
return false; return false;
@@ -195,7 +192,7 @@ public class NvidiaGpuControl : IGpuControl
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.WriteLine("SET GPU CLOCKS: "+ex.Message); Logger.WriteLine("SET GPU CLOCKS: " + ex.Message);
return -1; return -1;
} }

View File

@@ -179,4 +179,38 @@ public static class HardwareControl
Debug.WriteLine(ex.ToString()); Debug.WriteLine(ex.ToString());
} }
} }
public static void KillGPUApps()
{
List<string> tokill = new() { "EADesktop", "RadeonSoftware", "epicgameslauncher" };
if (AppConfig.isConfig("kill_gpu_apps"))
{
tokill.Add("nvdisplay.container");
tokill.Add("nvcontainer");
tokill.Add("nvcplui");
}
foreach (string kill in tokill)
foreach (var process in Process.GetProcessesByName(kill))
{
try
{
process.Kill();
Logger.WriteLine($"Stopped: {process.ProcessName}");
}
catch (Exception ex)
{
Logger.WriteLine($"Failed to stop: {process.ProcessName} {ex.Message}");
}
}
if (AppConfig.isConfig("kill_gpu_apps") && GpuControl is not null && GpuControl.IsNvidia)
{
NvidiaGpuControl nvControl = (NvidiaGpuControl)GpuControl;
nvControl.KillGPUApps();
}
}
} }

View File

@@ -1,10 +1,8 @@
using HidLibrary; using HidLibrary;
using Microsoft.Win32; using Microsoft.Win32;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Management; using System.Management;
using Tools;
namespace GHelper namespace GHelper
{ {
@@ -57,34 +55,22 @@ namespace GHelper
System.Timers.Timer timer = new System.Timers.Timer(1000); System.Timers.Timer timer = new System.Timers.Timer(1000);
public bool backlight = true; public bool backlight = true;
private static nint windowHandle;
public static Keys keyProfile = Keys.F5; public static Keys keyProfile = Keys.F5;
public static Keys keyApp = Keys.F12; public static Keys keyApp = Keys.F12;
KeyboardListener listener; KeyboardListener listener;
KeyboardHook hook = new KeyboardHook();
KeyHandler m1, m2, handlerProfile, handlerApp; public InputDispatcher()
public InputDispatcher(nint handle)
{ {
windowHandle = handle;
byte[] result = Program.acpi.DeviceInit(); byte[] result = Program.acpi.DeviceInit();
Debug.WriteLine($"Init: {BitConverter.ToString(result)}"); Debug.WriteLine($"Init: {BitConverter.ToString(result)}");
Program.acpi.SubscribeToEvents(WatcherEventArrived); Program.acpi.SubscribeToEvents(WatcherEventArrived);
//Task.Run(Program.acpi.RunListener); //Task.Run(Program.acpi.RunListener);
// CTRL + SHIFT + F5 to cycle profiles hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(KeyPressed);
if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile");
handlerProfile = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, keyProfile, windowHandle);
handlerApp = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, keyApp, windowHandle);
m1 = new KeyHandler(KeyHandler.NOMOD, Keys.VolumeDown, windowHandle);
m2 = new KeyHandler(KeyHandler.NOMOD, Keys.VolumeUp, windowHandle);
RegisterKeys(); RegisterKeys();
@@ -100,7 +86,7 @@ namespace GHelper
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online) if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
kb_timeout = AppConfig.getConfig("keyboard_ac_timeout", 0); kb_timeout = AppConfig.getConfig("keyboard_ac_timeout", 0);
else else
kb_timeout = AppConfig.getConfig("keyboard_timeout", 60); kb_timeout = AppConfig.getConfig("keyboard_timeout", 60);
if (kb_timeout == 0) return; if (kb_timeout == 0) return;
@@ -142,20 +128,25 @@ namespace GHelper
public void RegisterKeys() public void RegisterKeys()
{ {
// 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");
string actionM1 = AppConfig.getConfigString("m1"); string actionM1 = AppConfig.getConfigString("m1");
string actionM2 = AppConfig.getConfigString("m2"); string actionM2 = AppConfig.getConfigString("m2");
handlerProfile.Unregiser(); hook.UnregisterAll();
m1.Unregiser();
m2.Unregiser();
if (keyProfile != Keys.None) handlerProfile.Register(); if (keyProfile != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyProfile);
if (keyApp != Keys.None) handlerApp.Register(); if (keyApp != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyApp);
if (actionM1 is not null && actionM1.Length > 0) m1.Register(); 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 (actionM2 is not null && actionM2.Length > 0) m2.Register(); // FN-Lock group
if (AppConfig.isConfig("fn_lock"))
for (Keys i = Keys.F1; i < Keys.F12; i++) hook.RegisterHotKey(ModifierKeys.None, i);
} }
@@ -175,12 +166,75 @@ namespace GHelper
if (intKey > 0) if (intKey > 0)
NativeMethods.KeyPress(intKey); KeyboardHook.KeyPress((Keys)intKey);
else else
LaunchProcess(command); LaunchProcess(command);
} }
public void KeyPressed(object sender, KeyPressedEventArgs e)
{
if (e.Modifier == ModifierKeys.None)
{
Debug.WriteLine(e.Key);
switch (e.Key)
{
case Keys.F1:
KeyboardHook.KeyPress(Keys.VolumeMute);
break;
case Keys.F2:
HandleEvent(197);
break;
case Keys.F3:
HandleEvent(196);
break;
case Keys.F4:
KeyProcess("fnf4");
break;
case Keys.F5:
KeyProcess("fnf5");
break;
case Keys.F6:
KeyboardHook.KeyPress(Keys.Snapshot);
break;
case Keys.F7:
HandleEvent(16);
break;
case Keys.F8:
HandleEvent(32);
break;
case Keys.F9:
break;
case Keys.F10:
HandleEvent(107);
break;
case Keys.F11:
HandleEvent(108);
break;
case Keys.F12:
break;
case Keys.VolumeDown:
KeyProcess("m1");
break;
case Keys.VolumeUp:
KeyProcess("m2");
break;
default:
break;
}
}
if (e.Modifier == (ModifierKeys.Control | ModifierKeys.Shift))
{
if (e.Key == keyProfile) Program.settingsForm.CyclePerformanceMode();
if (e.Key == keyApp) Program.SettingsToggle();
}
}
public static void KeyProcess(string name = "m3") public static void KeyProcess(string name = "m3")
{ {
string action = AppConfig.getConfigString(name); string action = AppConfig.getConfigString(name);
@@ -200,13 +254,13 @@ namespace GHelper
switch (action) switch (action)
{ {
case "mute": case "mute":
NativeMethods.KeyPress(NativeMethods.VK_VOLUME_MUTE); KeyboardHook.KeyPress(Keys.VolumeMute);
break; break;
case "play": case "play":
NativeMethods.KeyPress(NativeMethods.VK_MEDIA_PLAY_PAUSE); KeyboardHook.KeyPress(Keys.MediaPlayPause);
break; break;
case "screenshot": case "screenshot":
NativeMethods.KeyPress(NativeMethods.VK_SNAPSHOT); KeyboardHook.KeyPress(Keys.Snapshot);
break; break;
case "screen": case "screen":
NativeMethods.TurnOffScreen(Program.settingsForm.Handle); NativeMethods.TurnOffScreen(Program.settingsForm.Handle);

164
app/KeyboardHook.cs Normal file
View File

@@ -0,0 +1,164 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
public sealed class KeyboardHook : IDisposable
{
// Registers a hot key with Windows.
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
// Unregisters the hot key with Windows.
[DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[DllImport("user32.dll")]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
public const int KEYEVENTF_EXTENDEDKEY = 1;
public const int KEYEVENTF_KEYUP = 2;
public static void KeyPress(Keys key)
{
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
}
/// <summary>
/// Represents the window that is used internally to get the messages.
/// </summary>
private class Window : NativeWindow, IDisposable
{
private static int WM_HOTKEY = 0x0312;
public static Keys? fakeKey;
public Window()
{
// create the handle for the window.
this.CreateHandle(new CreateParams());
}
/// <summary>
/// Overridden to get the notifications.
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
// check if we got a hot key pressed.
if (m.Msg == WM_HOTKEY)
{
// get the keys.
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF);
// invoke the event to notify the parent.
if (KeyPressed != null)
KeyPressed(this, new KeyPressedEventArgs(modifier, key));
}
}
public event EventHandler<KeyPressedEventArgs> KeyPressed;
#region IDisposable Members
public void Dispose()
{
this.DestroyHandle();
}
#endregion
}
private Window _window = new Window();
private int _currentId;
public KeyboardHook()
{
// register the event of the inner native window.
_window.KeyPressed += delegate (object sender, KeyPressedEventArgs args)
{
if (KeyPressed != null)
KeyPressed(this, args);
};
}
/// <summary>
/// Registers a hot key in the system.
/// </summary>
/// <param name="modifier">The modifiers that are associated with the hot key.</param>
/// <param name="key">The key itself that is associated with the hot key.</param>
public void RegisterHotKey(ModifierKeys modifier, Keys key)
{
// increment the counter.
_currentId = _currentId + 1;
// register the hot key.
if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
throw new InvalidOperationException("Couldnt register the hot key.");
}
/// <summary>
/// A hot key has been pressed.
/// </summary>
public event EventHandler<KeyPressedEventArgs> KeyPressed;
#region IDisposable Members
public void UnregisterAll()
{
// unregister all the registered hot keys.
for (int i = _currentId; i > 0; i--)
{
UnregisterHotKey(_window.Handle, i);
}
}
public void Dispose()
{
UnregisterAll();
// dispose the inner native window.
_window.Dispose();
}
#endregion
}
/// <summary>
/// Event Args for the event that is fired after the hot key has been pressed.
/// </summary>
public class KeyPressedEventArgs : EventArgs
{
private ModifierKeys _modifier;
private Keys _key;
internal KeyPressedEventArgs(ModifierKeys modifier, Keys key)
{
_modifier = modifier;
_key = key;
}
public ModifierKeys Modifier
{
get { return _modifier; }
}
public Keys Key
{
get { return _key; }
}
}
/// <summary>
/// The enumeration of possible modifiers.
/// </summary>
[Flags]
public enum ModifierKeys : uint
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Win = 8
}

View File

@@ -1,54 +1,11 @@
using GHelper; 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
{ {
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 static class ScreenInterrogatory
{ {
@@ -459,24 +416,6 @@ public class NativeMethods
public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent); public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent);
public const int KEYEVENTF_EXTENDEDKEY = 1;
public const int KEYEVENTF_KEYUP = 2;
public const int VK_MEDIA_NEXT_TRACK = 0xB0;
public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
public const int VK_MEDIA_PREV_TRACK = 0xB1;
public const int VK_VOLUME_MUTE = 0xAD;
public const int VK_SNAPSHOT = 0x2C;
[DllImport("user32.dll", SetLastError = true)]
public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
public static void KeyPress(int key = VK_MEDIA_PLAY_PAUSE)
{
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
}
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
public const int SW_RESTORE = 9; public const int SW_RESTORE = 9;

View File

@@ -77,7 +77,7 @@ namespace GHelper
trayIcon.MouseClick += TrayIcon_MouseClick; trayIcon.MouseClick += TrayIcon_MouseClick;
inputDispatcher = new InputDispatcher(ds); inputDispatcher = new InputDispatcher();
settingsForm.InitAura(); settingsForm.InitAura();
settingsForm.InitMatrix(); settingsForm.InitMatrix();

View File

@@ -193,7 +193,7 @@
<value>Apagar con batería tras (segundos)</value> <value>Apagar con batería tras (segundos)</value>
</data> </data>
<data name="BacklightTimeoutPlugged" xml:space="preserve"> <data name="BacklightTimeoutPlugged" xml:space="preserve">
<value>Apagar cuando está enchufado tras (0 - siempre encendida)</value> <value>Apagar cuando está enchufado tras (0 - nunca)</value>
</data> </data>
<data name="Balanced" xml:space="preserve"> <data name="Balanced" xml:space="preserve">
<value>Equilibrado</value> <value>Equilibrado</value>
@@ -307,7 +307,7 @@
<value>Bajar retroiluminación con batería</value> <value>Bajar retroiluminación con batería</value>
</data> </data>
<data name="KillGpuApps" xml:space="preserve"> <data name="KillGpuApps" xml:space="preserve">
<value>Detener todas las aplicaciones que usan la GPU cuando se cambia a Eco</value> <value>Detener todas las aplicaciones que usan la dGPU cuando se cambia a Eco</value>
</data> </data>
<data name="LaptopBacklight" xml:space="preserve"> <data name="LaptopBacklight" xml:space="preserve">
<value>Retroiluminación</value> <value>Retroiluminación</value>

View File

@@ -209,26 +209,6 @@ namespace GHelper
} }
m.Result = (IntPtr)1; m.Result = (IntPtr)1;
break; 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();
if (key == InputDispatcher.keyApp) Program.SettingsToggle();
break;
}
break;
} }
try try
@@ -338,7 +318,7 @@ namespace GHelper
if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1) if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1)
{ {
KillGPUApps(); HardwareControl.KillGPUApps();
DialogResult dialogResult = MessageBox.Show("Did you close all applications running on XG Mobile?", "Disabling XG Mobile", MessageBoxButtons.YesNo); DialogResult dialogResult = MessageBox.Show("Did you close all applications running on XG Mobile?", "Disabling XG Mobile", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
@@ -973,8 +953,8 @@ namespace GHelper
labelBattery.Text = battery; labelBattery.Text = battery;
}); });
string trayTip = "CPU" + cpuTemp + HardwareControl.cpuFan; string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;
if (gpuTemp.Length > 0) trayTip += "\nGPU" + gpuTemp + HardwareControl.gpuFan; if (gpuTemp.Length > 0) trayTip += "\nGPU" + gpuTemp + " " + HardwareControl.gpuFan;
if (battery.Length > 0) trayTip += "\n" + battery; if (battery.Length > 0) trayTip += "\n" + battery;
Program.trayIcon.Text = trayTip; Program.trayIcon.Text = trayTip;
@@ -1302,10 +1282,14 @@ namespace GHelper
int backlight = AppConfig.getConfig("keyboard_brightness"); int backlight = AppConfig.getConfig("keyboard_brightness");
if (AppConfig.isConfig("keyboard_auto") && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online) if (backlight > 0)
AsusUSB.ApplyBrightness(0); {
else if (backlight >= 0) if (AppConfig.isConfig("keyboard_auto") && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)
AsusUSB.ApplyBrightness(backlight); AsusUSB.ApplyBrightness(1);
else
AsusUSB.ApplyBrightness(backlight);
}
} }
@@ -1535,29 +1519,6 @@ namespace GHelper
} }
protected static void KillGPUApps()
{
string[] tokill = { "EADesktop", "RadeonSoftware", "epicgameslauncher", "nvdisplay.container", "nvcontainer", "nvcplui" };
foreach (string kill in tokill)
foreach (var process in Process.GetProcessesByName(kill))
{
try
{
process.Kill();
Logger.WriteLine($"Stopped: {process.ProcessName}");
} catch (Exception ex)
{
Logger.WriteLine($"Failed to stop: {process.ProcessName} {ex.Message}");
}
}
if (AppConfig.isConfig("kill_gpu_apps") && HardwareControl.GpuControl is not null && HardwareControl.GpuControl.IsNvidia)
{
NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
nvControl.KillGPUApps();
}
}
public void SetGPUEco(int eco, bool hardWay = false) public void SetGPUEco(int eco, bool hardWay = false)
{ {
@@ -1575,7 +1536,7 @@ namespace GHelper
int status = 1; int status = 1;
if (eco == 1) KillGPUApps(); if (eco == 1) HardwareControl.KillGPUApps();
Logger.WriteLine($"Running eco command {eco}"); Logger.WriteLine($"Running eco command {eco}");