From 291189347f9d1b68227d6f25000c7d6bd862a39e Mon Sep 17 00:00:00 2001 From: Yuri Gabriel <97139700+Yuuh15@users.noreply.github.com> Date: Sat, 3 Feb 2024 14:37:45 -0300 Subject: [PATCH] Add toggle "sticky keys" (#1546) Adds a toggle to enable/disable sticky keys --- config/tweaks.json | 8 +++ functions/private/Get-WinUtilToggleStatus.ps1 | 9 ++++ functions/private/Invoke-WinUtilStickyKeys | 31 ++++++++++++ functions/public/Invoke-WPFToggle.ps1 | 1 + winutil.ps1 | 49 +++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 functions/private/Invoke-WinUtilStickyKeys diff --git a/config/tweaks.json b/config/tweaks.json index e9d5873ad5..9f9bfb9ff7 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -2602,6 +2602,14 @@ "Order": "a066_", "Type": "Toggle" }, + "WPFToggleStickyKeys": { + "Content": "Sticky Keys", + "Description": "If Enabled then Sticky Keys is activated - Sticky keys is an accessibility feature of some graphical user interfaces which assists users who have physical disabilities or help users reduce repetitive strain injury.", + "category": "Customize Preferences", + "panel": "2", + "Order": "a067_", + "Type": "Toggle" + }, "WPFchangedns": { "Content": "DNS", "category": "z__Advanced Tweaks - CAUTION", diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index 43339c5beb..cc5b5090ce 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -80,4 +80,13 @@ Function Get-WinUtilToggleStatus { return $false } } + if ($ToggleSwitch -eq "WPFToggleStickyKeys") { + $StickyKeys = (Get-ItemProperty -path 'HKCU:\Control Panel\Accessibility\StickyKeys').Flags + if($StickyKeys -eq 58){ + return $false + } + else{ + return $true + } + } } \ No newline at end of file diff --git a/functions/private/Invoke-WinUtilStickyKeys b/functions/private/Invoke-WinUtilStickyKeys new file mode 100644 index 0000000000..3cd6433536 --- /dev/null +++ b/functions/private/Invoke-WinUtilStickyKeys @@ -0,0 +1,31 @@ +Function Invoke-WinUtilStickyKeys { + <# + .SYNOPSIS + Disables/Enables Sticky Keyss on startup + .PARAMETER Enabled + Indicates whether to enable or disable Sticky Keys on startup + #> + Param($Enabled) + Try { + if ($Enabled -eq $false){ + Write-Host "Enabling Sticky Keys On startup" + $value = 510 + } + else { + Write-Host "Disabling Sticky Keys On startup" + $value = 58 + } + $Path = "HKCU:\Control Panel\Accessibility\StickyKeys" + Set-ItemProperty -Path $Path -Name Flags -Value $value + } + Catch [System.Security.SecurityException] { + Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" + } + Catch [System.Management.Automation.ItemNotFoundException] { + Write-Warning $psitem.Exception.ErrorRecord + } + Catch{ + Write-Warning "Unable to set $Name due to unhandled exception" + Write-Warning $psitem.Exception.StackTrace + } +} \ No newline at end of file diff --git a/functions/public/Invoke-WPFToggle.ps1 b/functions/public/Invoke-WPFToggle.ps1 index 826abeaa80..1a60217e78 100644 --- a/functions/public/Invoke-WPFToggle.ps1 +++ b/functions/public/Invoke-WPFToggle.ps1 @@ -24,5 +24,6 @@ function Invoke-WPFToggle { "WPFToggleShowExt" {Invoke-WinUtilShowExt $(Get-WinUtilToggleStatus WPFToggleShowExt)} "WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $(Get-WinUtilToggleStatus WPFToggleSnapFlyout)} "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $(Get-WinUtilToggleStatus WPFToggleMouseAcceleration)} + "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $(Get-WinUtilToggleStatus WPFToggleStickyKeys)} } } \ No newline at end of file diff --git a/winutil.ps1 b/winutil.ps1 index c725aea831..130e436617 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -473,6 +473,15 @@ Function Get-WinUtilToggleStatus { return $false } } + if ($ToggleSwitch -eq "WPFToggleStickyKeys") { + $StickyKeys = (Get-ItemProperty -path 'HKCU:\Control Panel\Accessibility\StickyKeys').Flags + if($StickyKeys -eq 58){ + return $false + } + else{ + return $true + } + } } function Get-WinUtilVariables { @@ -1672,6 +1681,37 @@ function Invoke-WinUtilSnapFlyout { Write-Warning $psitem.Exception.StackTrace } } +Function Invoke-WinUtilStickyKeys { + <# + .SYNOPSIS + Disables/Enables Sticky Keyss on startup + .PARAMETER Enabled + Indicates whether to enable or disable Sticky Keys on startup + #> + Param($Enabled) + Try { + if ($Enabled -eq $false){ + Write-Host "Enabling Sticky Keys On startup" + $value = 510 + } + else { + Write-Host "Disabling Sticky Keys On startup" + $value = 58 + } + $Path = "HKCU:\Control Panel\Accessibility\StickyKeys" + Set-ItemProperty -Path $Path -Name Flags -Value $value + } + Catch [System.Security.SecurityException] { + Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" + } + Catch [System.Management.Automation.ItemNotFoundException] { + Write-Warning $psitem.Exception.ErrorRecord + } + Catch{ + Write-Warning "Unable to set $Name due to unhandled exception" + Write-Warning $psitem.Exception.StackTrace + } +} function Invoke-WinUtilTweaks { <# @@ -3905,6 +3945,7 @@ function Invoke-WPFToggle { "WPFToggleShowExt" {Invoke-WinUtilShowExt $(Get-WinUtilToggleStatus WPFToggleShowExt)} "WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $(Get-WinUtilToggleStatus WPFToggleSnapFlyout)} "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $(Get-WinUtilToggleStatus WPFToggleMouseAcceleration)} + "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $(Get-WinUtilToggleStatus WPFToggleStickyKeys)} } } function Invoke-WPFtweaksbutton { @@ -10618,6 +10659,14 @@ $sync.configs.tweaks = '{ "Order": "a066_", "Type": "Toggle" }, + "WPFToggleStickyKeys": { + "Content": "Sticky Keys", + "Description": "If Enabled then Sticky Keys is activated - Sticky keys is an accessibility feature of some graphical user interfaces which assists users who have physical disabilities or help users reduce repetitive strain injury.", + "category": "Customize Preferences", + "panel": "2", + "Order": "a067_", + "Type": "Toggle" + }, "WPFchangedns": { "Content": "DNS", "category": "z__Advanced Tweaks - CAUTION",