Last active
December 9, 2022 07:28
-
-
Save spddl/eb001e2eafe238520127c124413db966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $VerbosePreference = "continue" | |
$TestValues = [System.Collections.ArrayList]( | |
[PSCustomObject]@{ | |
Description = "Short, Fixed, High foreground boost." | |
HexValue = "2A" | |
DecValue = "42" | |
}, | |
[PSCustomObject]@{ | |
Description = "Short, Fixed, Medium foreground boost." | |
HexValue = "29" | |
DecValue = "41" | |
}, | |
[PSCustomObject]@{ | |
Description = "Short, Fixed, No foreground boost." | |
HexValue = "28" | |
DecValue = "40" | |
}, | |
[PSCustomObject]@{ | |
Description = "Short, Variable, High foreground boost." | |
HexValue = "26" | |
DecValue = "38" | |
}, | |
[PSCustomObject]@{ | |
Description = "Short, Variable, Medium foreground boost." | |
HexValue = "25" | |
DecValue = "37" | |
}, | |
[PSCustomObject]@{ | |
Description = "Short, Variable, No foreground boost." | |
HexValue = "24" | |
DecValue = "36" | |
}, | |
[PSCustomObject]@{ | |
Description = "Long, Fixed, High foreground boost." | |
HexValue = "1A" | |
DecValue = "26" | |
}, | |
[PSCustomObject]@{ | |
Description = "Long, Fixed, Medium foreground boost." | |
HexValue = "19" | |
DecValue = "25" | |
}, | |
[PSCustomObject]@{ | |
Description = "Long, Fixed, No foreground boost." | |
HexValue = "18" | |
DecValue = "24" | |
}, | |
[PSCustomObject]@{ | |
Description = "Long, Variable, High foreground boost." | |
HexValue = "16" | |
DecValue = "22" | |
}, | |
[PSCustomObject]@{ | |
Description = "Long, Variable, Medium foreground boost." | |
HexValue = "15" | |
DecValue = "21" | |
}, | |
[PSCustomObject]@{ | |
Description = "Long, Variable, No foreground boost." | |
HexValue = "14" | |
DecValue = "20" | |
} | |
) | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Drawing | |
[System.Collections.ArrayList]$BlindValues = @() | |
$len = $TestValues.Count | |
for ($i = 1; $i -le $len; $i++) { | |
$index = Get-Random -Maximum $TestValues.Count | |
$BlindValues.Add($TestValues[$index]) | Out-Null | |
$TestValues.RemoveAt($index) | |
} | |
$BlindValues | ForEach-Object { | |
Write-Verbose "0x$($_.HexValue)/$($_.DecValue) = $($_.Description)" | |
} | |
function MoveItem ([int]$direction) { | |
# Checking selected item | |
if ($listBox.SelectedItem -eq "" -or $listBox.SelectedIndex -lt 0) { | |
return # No selected item - nothing to do | |
} | |
# Calculate new index using move direction | |
[int]$newIndex = $listBox.SelectedIndex + $direction | |
# Checking bounds of the range | |
if ($newIndex -lt 0 -or $newIndex -ge $listBox.Items.Count) { | |
return # Index out of range - nothing to do | |
} | |
$selected = $listBox.SelectedItem | |
# Removing removable element | |
$listBox.Items.Remove($selected) | |
# Insert it in new position | |
$listBox.Items.Insert($newIndex, $selected) | |
# Restore selection | |
$listBox.SetSelected($newIndex, $true) | |
} | |
$form = New-Object System.Windows.Forms.Form | |
$form.ShowIcon = $false | |
$form.MaximizeBox = $false | |
$form.MinimizeBox = $false | |
$form.Text = 'Blind Test Win32ps' | |
$form.Size = New-Object System.Drawing.Size(410, 240) | |
$form.StartPosition = 'CenterScreen' | |
$Form.AutoSizeMode = 0 | |
$Form.KeyPreview = $True | |
$Form.SizeGripStyle = 2 | |
$solutionButton = New-Object System.Windows.Forms.Button | |
$solutionButton.Location = New-Object System.Drawing.Point(290, 15) | |
$solutionButton.Size = New-Object System.Drawing.Size(80, 23) | |
$solutionButton.Text = 'solution' | |
$solutionButton.Add_click({ | |
for ($i = 0; $i -lt $BlindValues.Count; $i++) { | |
$space = $listBox.Items[$i].IndexOf(" ") | |
[int]$index = $listBox.Items[$i].substring(0, $space) | |
$val = $BlindValues[$index] | |
$listBox.Items[$i] = "0x$($val.HexValue)/$($val.DecValue) = $($val.Description)" | |
} | |
}) | |
$form.Controls.Add($solutionButton) | |
$moveUpButton = New-Object System.Windows.Forms.Button | |
$moveUpButton.Location = New-Object System.Drawing.Point(290, 55) | |
$moveUpButton.Size = New-Object System.Drawing.Size(80, 23) | |
$moveUpButton.Text = 'Move up' | |
$moveUpButton.Add_click({MoveItem(-1)}) | |
$form.Controls.Add($moveUpButton) | |
$moveUpButton = New-Object System.Windows.Forms.Button | |
$moveUpButton.Location = New-Object System.Drawing.Point(290, 95) | |
$moveUpButton.Size = New-Object System.Drawing.Size(80, 23) | |
$moveUpButton.Text = 'Move down' | |
$moveUpButton.Add_click({MoveItem(1)}) | |
$form.Controls.Add($moveUpButton) | |
$listBox = New-Object System.Windows.Forms.ListBox | |
$listBox.Location = New-Object System.Drawing.Point(10,15) | |
$listBox.Size = New-Object System.Drawing.Size(260,20) | |
$listBox.Height = 180 | |
$listBox.Add_click({ | |
$val = $BlindValues[$listBox.SelectedIndex] | |
Write-Verbose "Set: $($val.DecValue) => $($val.Description)" | |
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\PriorityControl -Name Win32PrioritySeparation -Type DWord -Value $val.DecValue | |
}) | |
for ($i = 0; $i -lt $BlindValues.Count; $i++) { | |
[void] $listBox.Items.Add("$i TestValue") | |
} | |
$form.Controls.Add($listBox) | |
$form.Topmost = $true | |
[void]$form.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment