Skip to content

Instantly share code, notes, and snippets.

@james-hinton
Last active March 20, 2024 17:07
Show Gist options
  • Save james-hinton/12a7899caae915f16e2f614f97b3be6c to your computer and use it in GitHub Desktop.
Save james-hinton/12a7899caae915f16e2f614f97b3be6c to your computer and use it in GitHub Desktop.
A PowerShell script for quickly toggling between duplicate and extend display modes on Windows
# Path to custom registry key for tracking display mode
$registryPath = "HKCU:\Software\CustomDisplayToggle"
$keyName = "DisplayMode"
if (-not (Test-Path $registryPath)) {
New-Item -Path $registryPath -Force | Out-Null
New-ItemProperty -Path $registryPath -Name $keyName -Value "Duplicate" -PropertyType String -Force | Out-Null
}
Start-Sleep -Seconds 1
$currentMode = (Get-ItemProperty -Path $registryPath).$keyName
if ($currentMode -eq "Duplicate") {
# switch to Extend
DisplaySwitch.exe /extend
Set-ItemProperty -Path $registryPath -Name $keyName -Value "Extend"
} else {
# switch to Duplicate
DisplaySwitch.exe /clone
Set-ItemProperty -Path $registryPath -Name $keyName -Value "Duplicate"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment