From 697b5f0d2f0a19a526d5103a5277f41f5910e915 Mon Sep 17 00:00:00 2001
From: Serge <5920850+seerge@users.noreply.github.com>
Date: Wed, 14 Feb 2024 09:41:50 +0100
Subject: [PATCH] Camera toggle for old Vivobooks
https://github.com/seerge/g-helper/issues/2060
---
app/AsusACPI.cs | 5 +++--
app/GHelper.csproj | 2 +-
app/Input/InputDispatcher.cs | 27 ++++++++++++++++++++++++++-
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs
index 36df33eb..90a27a71 100644
--- a/app/AsusACPI.cs
+++ b/app/AsusACPI.cs
@@ -46,7 +46,6 @@ public class AsusACPI
public const int KB_DUO_PgUpDn = 0x4B;
public const int KB_DUO_SecondDisplay = 0x6A;
-
public const int Touchpad_Toggle = 0x6B;
public const int ChargerMode = 0x0012006C;
@@ -106,7 +105,7 @@ public class AsusACPI
public const int TUF_KB2 = 0x0010005a;
public const int TUF_KB_STATE = 0x00100057;
- public const int MICMUTE_LED = 0x00040017;
+ public const int MicMuteLed = 0x00040017;
public const int TabletState = 0x00060077;
public const int FnLock = 0x00100023;
@@ -114,6 +113,8 @@ public class AsusACPI
public const int ScreenPadToggle = 0x00050031;
public const int ScreenPadBrightness = 0x00050032;
+ public const int CameraLed = 0x00060079;
+
public const int BootSound = 0x00130022;
public const int Tablet_Notebook = 0;
diff --git a/app/GHelper.csproj b/app/GHelper.csproj
index a390d6e6..272440aa 100644
--- a/app/GHelper.csproj
+++ b/app/GHelper.csproj
@@ -15,7 +15,7 @@
AnyCPU
False
True
- 0.153
+ 0.154
diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs
index e1bb2835..8eafcb76 100644
--- a/app/Input/InputDispatcher.cs
+++ b/app/Input/InputDispatcher.cs
@@ -500,7 +500,7 @@ namespace GHelper.Input
case "micmute":
bool muteStatus = Audio.ToggleMute();
Program.toast.RunToast(muteStatus ? "Muted" : "Unmuted", muteStatus ? ToastIcon.MicrophoneMute : ToastIcon.Microphone);
- if (AppConfig.IsVivobook()) Program.acpi.DeviceSet(AsusACPI.MICMUTE_LED, muteStatus ? 1 : 0, "MicmuteLed");
+ if (AppConfig.IsVivobook()) Program.acpi.DeviceSet(AsusACPI.MicMuteLed, muteStatus ? 1 : 0, "MicmuteLed");
break;
case "brightness_up":
SetBrightness(+10);
@@ -628,6 +628,9 @@ namespace GHelper.Input
{
switch (EventID)
{
+ case 134: // FN + F12 ON OLD DEVICES
+ KeyProcess("m4");
+ return;
case 124: // M3
KeyProcess("m3");
return;
@@ -706,6 +709,9 @@ namespace GHelper.Input
else
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.Brightness_Up, "Brightness");
break;
+ case 133: // Camera Toggle
+ ToggleCamera();
+ break;
case 107: // FN+F10
ToggleTouchpadEvent();
break;
@@ -784,6 +790,25 @@ namespace GHelper.Input
Program.toast.RunToast($"Screen Pad " + (toggle == 1 ? "On" : "Off"), toggle > 0 ? ToastIcon.BrightnessUp : ToastIcon.BrightnessDown);
}
+ public static void ToggleCamera()
+ {
+ if (!ProcessHelper.IsUserAdministrator()) return;
+
+ int toggle = AppConfig.Is("camera_toggle") ? 0 : 1;
+ Program.acpi.DeviceSet(AsusACPI.CameraLed, toggle, "Camera");
+
+ try
+ {
+ ProcessHelper.RunCMD("powershell", (toggle == 1 ? "Disable" : "Enable") + "-PnpDevice -InstanceId (Get-PnpDevice -FriendlyName *webcam*).InstanceId -Confirm:$false");
+ }
+ catch (Exception ex)
+ {
+ Logger.WriteLine(ex.ToString());
+ }
+
+ AppConfig.Set("camera_toggle", toggle);
+ Program.toast.RunToast($"Camera " + (toggle == 1 ? "Off" : "On"));
+ }
public static void SetScreenpad(int delta)
{