From 3fc5d6a124f56416f420942e171a72788a8084dd Mon Sep 17 00:00:00 2001
From: Serge <5920850+seerge@users.noreply.github.com>
Date: Mon, 1 Apr 2024 14:22:29 +0200
Subject: [PATCH] Added option to lock screen
https://github.com/seerge/g-helper/issues/2352
---
app/Extra.cs | 1 +
app/Input/InputDispatcher.cs | 4 ++++
app/NativeMethods.cs | 9 +++++++++
app/Properties/Strings.Designer.cs | 9 +++++++++
app/Properties/Strings.resx | 3 +++
5 files changed, 26 insertions(+)
diff --git a/app/Extra.cs b/app/Extra.cs
index edd25b9f..431f0d5d 100644
--- a/app/Extra.cs
+++ b/app/Extra.cs
@@ -30,6 +30,7 @@ namespace GHelper
{"aura", Properties.Strings.ToggleAura},
{"performance", Properties.Strings.PerformanceMode},
{"screen", Properties.Strings.ToggleScreen},
+ {"lock", Properties.Strings.LockScreen},
{"miniled", Properties.Strings.ToggleMiniled},
{"fnlock", Properties.Strings.ToggleFnLock},
{"brightness_down", Properties.Strings.BrightnessDown},
diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs
index 566e1da2..2e4ecca1 100644
--- a/app/Input/InputDispatcher.cs
+++ b/app/Input/InputDispatcher.cs
@@ -473,6 +473,10 @@ namespace GHelper.Input
case "screenshot":
KeyboardHook.KeyPress(Keys.Snapshot);
break;
+ case "lock":
+ Logger.WriteLine("Screen lock");
+ NativeMethods.LockScreen();
+ break;
case "screen":
Logger.WriteLine("Screen off toggle");
NativeMethods.TurnOffScreen();
diff --git a/app/NativeMethods.cs b/app/NativeMethods.cs
index b7d24bfd..e532c89b 100644
--- a/app/NativeMethods.cs
+++ b/app/NativeMethods.cs
@@ -32,6 +32,15 @@ public class NativeMethods
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern uint FormatMessage(uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, out string lpBuffer, uint nSize, IntPtr Arguments);
+ [DllImport("user32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool LockWorkStation();
+
+ public static void LockScreen()
+ {
+ LockWorkStation();
+ }
+
public static void TurnOffScreen()
{
Form f = new Form();
diff --git a/app/Properties/Strings.Designer.cs b/app/Properties/Strings.Designer.cs
index cd370400..430929a1 100644
--- a/app/Properties/Strings.Designer.cs
+++ b/app/Properties/Strings.Designer.cs
@@ -1223,6 +1223,15 @@ namespace GHelper.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Lock Screen.
+ ///
+ internal static string LockScreen {
+ get {
+ return ResourceManager.GetString("LockScreen", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Logo.
///
diff --git a/app/Properties/Strings.resx b/app/Properties/Strings.resx
index b27501ab..21359f52 100644
--- a/app/Properties/Strings.resx
+++ b/app/Properties/Strings.resx
@@ -506,6 +506,9 @@ Do you still want to continue?
Lighting
+
+ Lock Screen
+
Logo