Skip to content

Commit

Permalink
Touchscreen toggle toast tweaks #3143
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Sep 23, 2024
1 parent 79cd773 commit c6d1b29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 15 additions & 5 deletions app/Helpers/TouchscreenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Expand Down
10 changes: 7 additions & 3 deletions app/Input/InputDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,13 @@ public static void KeyProcess(string name = "m3")
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;
Expand Down

0 comments on commit c6d1b29

Please sign in to comment.