Skip to content

Commit

Permalink
Add feature to set the resolution and refresh rate to the highest values
Browse files Browse the repository at this point in the history
  • Loading branch information
yuusakuri committed Jul 29, 2021
1 parent f2ed6ca commit 1493f86
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions functions/Set-Monitor.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
# Specify frequency (refresh rate).
[Alias('RefreshRate')]
[int]
$Frequency
$Frequency,

# Set the resolution and refresh rate to the highest values.
[switch]
$HighestQuality
)

begin {
Expand Down Expand Up @@ -94,18 +98,28 @@
ForEach-Object {
$aMonitor = $_

if (!$PSBoundParameters.ContainsKey('HorizontalResolution')) {
$HorizontalResolution = $aMonitor.horizontalResolution
if ($HighestQuality) {
$bestDisplayMode = $aMonitor.supportedDisplayModes |
Select-Object -Last 1

$HorizontalResolution = $bestDisplayMode.horizontalResolution
$VerticalResolution = $bestDisplayMode.verticalResolution
$Frequency = $bestDisplayMode.frequency
}
if (!$PSBoundParameters.ContainsKey('VerticalResolution')) {
$VerticalResolution = $aMonitor.verticalResolution
else {
if (!$PSBoundParameters.ContainsKey('HorizontalResolution')) {
$HorizontalResolution = $aMonitor.horizontalResolution
}
if (!$PSBoundParameters.ContainsKey('VerticalResolution')) {
$VerticalResolution = $aMonitor.verticalResolution
}
if (!$PSBoundParameters.ContainsKey('Frequency')) {
$Frequency = $aMonitor.frequency
}
}
if (!$PSBoundParameters.ContainsKey('BitsPerPixel')) {
$BitsPerPixel = $aMonitor.bitsPerPixel
}
if (!$PSBoundParameters.ContainsKey('Frequency')) {
$Frequency = $aMonitor.frequency
}
$monitorIndexForSetdisplay = ([int]$aMonitor.monitorIndex) - 1

$cmd = 'nircmd.exe setdisplay "monitor:{0}" "{1}" "{2}" "{3}" "{4}"' -f $monitorIndexForSetdisplay, $HorizontalResolution, $VerticalResolution, $BitsPerPixel, $Frequency
Expand Down

0 comments on commit 1493f86

Please sign in to comment.