Skip to content

Commit

Permalink
Touchscreen toggle binding #2575
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed May 11, 2024
1 parent 5b383b2 commit a0c15e6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private void SetKeyCombo(ComboBox combo, TextBox txbox, string name)
{"brightness_down", Properties.Strings.BrightnessDown},
{"brightness_up", Properties.Strings.BrightnessUp},
{"visual", Properties.Strings.VisualMode},
{"touchscreen", Properties.Strings.ToggleTouchscreen },
{"ghelper", Properties.Strings.OpenGHelper},
{"custom", Properties.Strings.Custom}
};
Expand Down
23 changes: 23 additions & 0 deletions app/Helpers/TouchscreenHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using GHelper.Helpers;

public static class TouchscreenHelper
{
public static bool? ToggleTouchscreen()
{
try
{
ProcessHelper.RunAsAdmin();

var status = !ProcessHelper.RunCMD("powershell", "(Get-PnpDevice -FriendlyName '*touch*screen*').Status").Contains("OK");
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;
}

}
}
5 changes: 5 additions & 0 deletions app/Input/InputDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ public static void KeyProcess(string name = "m3")
case "controller":
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);
break;
default:
break;
}
Expand Down
18 changes: 18 additions & 0 deletions app/Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/Properties/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,12 @@ Do you still want to continue?</value>
<data name="ToggleScreen" xml:space="preserve">
<value>Toggle Screen</value>
</data>
<data name="ToggleTouchscreen" xml:space="preserve">
<value>Toggle Touchscreen</value>
</data>
<data name="Touchscreen" xml:space="preserve">
<value />
</data>
<data name="Turbo" xml:space="preserve">
<value>Turbo</value>
</data>
Expand Down

0 comments on commit a0c15e6

Please sign in to comment.