mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Touchscreen toggle toast tweaks https://github.com/seerge/g-helper/issues/3143
This commit is contained in:
@@ -2,21 +2,31 @@
|
||||
|
||||
public static class TouchscreenHelper
|
||||
{
|
||||
public static bool? ToggleTouchscreen()
|
||||
|
||||
public static bool? GetStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessHelper.RunAsAdmin();
|
||||
return ProcessHelper.RunCMD("powershell", "(Get-PnpDevice -FriendlyName '*touch*screen*').Status").Contains("OK");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine($"Can't get touchscreen status: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var status = !ProcessHelper.RunCMD("powershell", "(Get-PnpDevice -FriendlyName '*touch*screen*').Status").Contains("OK");
|
||||
public static void ToggleTouchscreen(bool status)
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessHelper.RunAsAdmin();
|
||||
ProcessHelper.RunCMD("powershell", (status ? "Enable-PnpDevice" : "Disable-PnpDevice") + " -InstanceId (Get-PnpDevice -FriendlyName '*touch*screen*').InstanceId -Confirm:$false");
|
||||
|
||||
return status;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine($"Can't toggle touchscreen: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -591,9 +591,13 @@ namespace GHelper.Input
|
||||
Program.settingsForm.BeginInvoke(Program.settingsForm.allyControl.ToggleModeHotkey);
|
||||
break;
|
||||
case "touchscreen":
|
||||
var touchscreenStatus = TouchscreenHelper.ToggleTouchscreen();
|
||||
if (touchscreenStatus is not null)
|
||||
Program.toast.RunToast(Properties.Strings.Touchscreen + " " + ((bool)touchscreenStatus ? Properties.Strings.On : Properties.Strings.Off), ToastIcon.Touchpad);
|
||||
var status = !TouchscreenHelper.GetStatus();
|
||||
Logger.WriteLine("Touchscreen status: " + status);
|
||||
if (status is not null)
|
||||
{
|
||||
Program.toast.RunToast(Properties.Strings.Touchscreen + " " + ((bool)status ? Properties.Strings.On : Properties.Strings.Off), ToastIcon.Touchpad);
|
||||
TouchscreenHelper.ToggleTouchscreen((bool)status);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user