Skip to content

Instantly share code, notes, and snippets.

@frostbitten
Created July 3, 2022 07:53
Show Gist options
  • Save frostbitten/b069ddf906d19d7913298ae88c18c111 to your computer and use it in GitHub Desktop.
Save frostbitten/b069ddf906d19d7913298ae88c18c111 to your computer and use it in GitHub Desktop.
autohotkey script to toggle touch screen with Win+P (laptop hotkey for projector)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#p:: ;Windows + P (projector button)
Run cmd /c start /min "" powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File .\ps-touch-toggle.ps1
return
$deviceID = Get-PnpDevice | Where-Object {$_.FriendlyName -like "*touch screen*"} | Select -ExpandProperty InstanceId
$deviceStatus = Get-PnpDevice | Where-Object {$_.InstanceId -eq $deviceID} | Select -ExpandProperty Status
$deviceID
$deviceStatus
if($deviceStatus -eq "Error")
{
Get-PnpDevice | Where-Object {$_.InstanceId -eq $deviceID} | Enable-PnpDevice -Confirm:$false
$deviceNewStatus = "Enabled"
}else{
Get-PnpDevice | Where-Object {$_.InstanceId -eq $deviceID} | Disable-PnpDevice -Confirm:$false
$deviceNewStatus = "Disabled"
}
Add-Type -AssemblyName System.Windows.Forms
$global:balmsg = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info
$balmsg.BalloonTipText = "Touch $deviceNewStatus"
$balmsg.BalloonTipTitle = "Touch $deviceNewStatus"
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment