Refactor Hotkey Handling to improve readability and fix a bug

This commit is contained in:
Marterich
2025-03-31 21:15:28 +02:00
parent 698f1644c3
commit ff9a590ede

View File

@ -250,51 +250,34 @@ $sync.SearchBarClearButton.Add_Click({
# add some shortcuts for people that don't like clicking # add some shortcuts for people that don't like clicking
$commonKeyEvents = { $commonKeyEvents = {
# Prevent shortcuts from executing if a process is already running
if ($sync.ProcessRunning -eq $true) { if ($sync.ProcessRunning -eq $true) {
return return
} }
if ($_.Key -eq "Escape") { # Handle key presses of single keys
$sync.SearchBar.SelectAll() switch ($_.Key) {
$sync.SearchBar.Text = "" "Escape" { $sync.SearchBar.Text = "" }
$sync.SearchBarClearButton.Visibility = "Collapsed"
return
}
# don't ask, I know what I'm doing, just go...
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl")) {
$this.Close()
} }
# Handle Alt key combinations for navigation
if ($_.KeyboardDevice.Modifiers -eq "Alt") { if ($_.KeyboardDevice.Modifiers -eq "Alt") {
if ($_.SystemKey -eq "I") { $keyEventArgs = $_
Invoke-WPFButton "WPFTab1BT" switch ($_.SystemKey) {
} "I" { Invoke-WPFButton "WPFTab1BT"; $keyEventArgs.Handled = $true } # Navigate to Install tab and suppress Windows Warning Sound
if ($_.SystemKey -eq "T") { "T" { Invoke-WPFButton "WPFTab2BT"; $keyEventArgs.Handled = $true } # Navigate to Tweaks tab
Invoke-WPFButton "WPFTab2BT" "C" { Invoke-WPFButton "WPFTab3BT"; $keyEventArgs.Handled = $true } # Navigate to Config tab
} "U" { Invoke-WPFButton "WPFTab4BT"; $keyEventArgs.Handled = $true } # Navigate to Updates tab
if ($_.SystemKey -eq "C") { "M" { Invoke-WPFButton "WPFTab5BT"; $keyEventArgs.Handled = $true } # Navigate to MicroWin tab
Invoke-WPFButton "WPFTab3BT"
}
if ($_.SystemKey -eq "U") {
Invoke-WPFButton "WPFTab4BT"
}
if ($_.SystemKey -eq "M") {
Invoke-WPFButton "WPFTab5BT"
}
if ($_.SystemKey -eq "P") {
Write-Host "Your Windows Product Key: $((Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey)"
} }
} }
# shortcut for the filter box # Handle Ctrl key combinations for specific actions
if ($_.Key -eq "F" -and $_.KeyboardDevice.Modifiers -eq "Ctrl") { if ($_.KeyboardDevice.Modifiers -eq "Ctrl") {
if ($sync.SearchBar.Text -eq "Ctrl-F to filter") { switch ($_.Key) {
$sync.SearchBar.SelectAll() "F" { $sync.SearchBar.Focus() } # Focus on the search bar
$sync.SearchBar.Text = "" "Q" { $this.Close() } # Close the application
} }
$sync.SearchBar.Focus()
} }
} }
$sync["Form"].Add_PreViewKeyDown($commonKeyEvents) $sync["Form"].Add_PreViewKeyDown($commonKeyEvents)
$sync["Form"].Add_MouseLeftButtonDown({ $sync["Form"].Add_MouseLeftButtonDown({