Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] - GUI script for accessibility shortcuts #1259

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
set "script=%windir%\AtlasModules\Scripts\ScriptWrappers\AccessibilityShortcuts.ps1"
if not exist "%script%" (
echo Script not found.
echo "%script%"
pause
exit /b 1
)
powershell -EP Bypass -NoP ^& """$env:script""" %*
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
[CmdletBinding()]
param()

function Test-Admin {
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentIdentity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

if (-not (Test-Admin)) {
Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$form = New-Object System.Windows.Forms.Form
$form.Text = "Accessibility Shortcuts"
$form.Size = New-Object System.Drawing.Size(400, 400)
$form.StartPosition = "CenterScreen"

function Toggle-Process {
param (
[string]$processName,
[scriptblock]$startCommand
)
$process = Get-Process -Name $processName -ErrorAction SilentlyContinue
if ($process) {
Stop-Process -Name $processName -Force
Start-Sleep -Milliseconds 500
} else {
& $startCommand
}
}

# Dark Mode/Light Mode Toggle
function dark_mode {
$form.BackColor = [System.Drawing.Color]::FromArgb(26, 26, 26)
$form.ForeColor = [System.Drawing.Color]::White
foreach ($control in $form.Controls) {
if ($control.GetType().Name -eq "Button") {
$control.BackColor = [System.Drawing.Color]::FromArgb(26, 26, 26)
$control.ForeColor = [System.Drawing.Color]::White
}
}
}

function light_mode {
$form.BackColor = [System.Drawing.Color]::FromArgb(240, 240, 240)
$form.ForeColor = [System.Drawing.Color]::Black
foreach ($control in $form.Controls) {
if ($control.GetType().Name -eq "Button") {
$control.BackColor = [System.Drawing.Color]::FromArgb(240, 240, 240)
$control.ForeColor = [System.Drawing.Color]::Black
}
}
}

$registryPath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"
$keyName = "AppsUseLightTheme"
function check_system_theme {
if (((Get-ItemProperty -Path $registryPath -Name $keyName).$keyName) -eq 0) {
dark_mode
$toggleBtn.Text = "Light Mode"
} else {
light_mode
$toggleBtn.Text = "Dark Mode"
}
}

$toggleBtn = New-Object System.Windows.Forms.Button
$toggleBtn.Location = New-Object System.Drawing.Point(300, 10)
$toggleBtn.Size = New-Object System.Drawing.Size(80, 23)
$toggleBtn.Add_Click({
if ($toggleBtn.Text -eq "Dark Mode") {
$toggleBtn.Text = "Light Mode"
dark_mode
} else {
$toggleBtn.Text = "Dark Mode"
light_mode
}
})
$form.Controls.Add($toggleBtn)

check_system_theme

$buttons = @(
@{Text = "Toggle Narrator"; Shortcut = "Ctrl + Win + Enter"; Handler = {
Toggle-Process -processName "Narrator" -startCommand { Start-Process "Narrator.exe" }
}},
@{Text = "Toggle Magnifier"; Shortcut = "Win + Plus/Minus"; Handler = {
Toggle-Process -processName "Magnify" -startCommand { Start-Process "Magnify.exe" }
}},
@{Text = "Toggle High Contrast"; Shortcut = "Alt + Shift + Print Screen"; Handler = {
Start-Process "ms-settings:easeofaccess-highcontrast"
}},
@{Text = "Open/Close On-Screen Keyboard"; Shortcut = "Win + Ctrl + O"; Handler = {
Toggle-Process -processName "osk" -startCommand { Start-Process "osk.exe" }
}},
@{Text = "Sticky Keys Settings"; Shortcut = "Shift Key (pressed 5 times)"; Handler = {
Start-Process "ms-settings:easeofaccess-keyboard"
}}
)

$yPos = 50
foreach ($buttonInfo in $buttons) {
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object System.Drawing.Size(350, 40)
$button.Location = New-Object System.Drawing.Point(20, $yPos)
$button.Text = "$($buttonInfo.Text) ($($buttonInfo.Shortcut))"
$button.Add_Click($buttonInfo.Handler)
$form.Controls.Add($button)
$yPos += 50
}

$form.Topmost = $true
[void]$form.ShowDialog()
Loading