If you play some games with HDR and others without it, this PowerShell launcher helps automate the switch so you don’t have to toggle HDR manually every time.
What this script does
- Toggles HDR ON before launching a Steam game
- Waits until the game process exits
- Toggles HDR back OFF after the game closes
PowerShell script (auto-detect Steam game, no GameID needed)
# Auto HDR Switcher for Steam (no GameID required)
# Watches for any Steam-launched game process and toggles HDR automatically.
param(
[int]$PollSeconds = 2,
[int]$PostLaunchGraceSeconds = 8
)
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class KeySender {
[DllImport("user32.dll", SetLastError=true)]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
}
"@
$VK_LWIN = 0x5B
$VK_MENU = 0x12
$VK_B = 0x42
$KEYEVENTF_KEYUP = 0x0002
function Invoke-HdrToggle {
[KeySender]::keybd_event($VK_LWIN,0,0,[UIntPtr]::Zero)
[KeySender]::keybd_event($VK_MENU,0,0,[UIntPtr]::Zero)
[KeySender]::keybd_event($VK_B,0,0,[UIntPtr]::Zero)
Start-Sleep -Milliseconds 120
[KeySender]::keybd_event($VK_B,0,$KEYEVENTF_KEYUP,[UIntPtr]::Zero)
[KeySender]::keybd_event($VK_MENU,0,$KEYEVENTF_KEYUP,[UIntPtr]::Zero)
[KeySender]::keybd_event($VK_LWIN,0,$KEYEVENTF_KEYUP,[UIntPtr]::Zero)
}
function Get-SteamGameProcesses {
# Steam.exe + gameoverlayui.exe are not game executables, so exclude them.
# We use parent-child relation where parent is Steam or steamwebhelper.
$all = Get-CimInstance Win32_Process
$steamParents = $all | Where-Object { $_.Name -in @('steam.exe','steamwebhelper.exe') } | Select-Object -ExpandProperty ProcessId
if (-not $steamParents) { return @() }
$children = $all | Where-Object {
$_.ParentProcessId -in $steamParents -and
$_.Name -notin @('steam.exe','steamwebhelper.exe','gameoverlayui.exe')
}
return $children
}
Write-Host "Watching for Steam game process..."
$hdrOn = $false
while ($true) {
$games = Get-SteamGameProcesses
if ($games.Count -gt 0 -and -not $hdrOn) {
Write-Host "Steam game detected: $($games[0].Name). Toggling HDR ON..."
Invoke-HdrToggle
$hdrOn = $true
Start-Sleep -Seconds $PostLaunchGraceSeconds
}
if ($games.Count -eq 0 -and $hdrOn) {
Write-Host "No Steam game running. Toggling HDR OFF..."
Invoke-HdrToggle
$hdrOn = $false
}
Start-Sleep -Seconds $PollSeconds
}
How to run in background
powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File .\AutoHDR-Steam.ps1
This mode keeps running in the background and automatically handles HDR based on Steam game activity.
Tips
- Use the real executable name from Task Manager for
-GameProcessName. - If your game takes longer to start, increase
-LaunchDelaySeconds. - Create one shortcut per game with its own Steam Game ID and process name.
Run it automatically in background (recommended)
To keep this truly automatic, run it through Task Scheduler or a startup shortcut so it launches silently when needed.
Task Scheduler example
# Program/script:
powershell.exe
# Add arguments:
-WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Scripts\AutoHDR-Steam.ps1" 1091500 -GameProcessName "Cyberpunk2077.exe"
This keeps the script in the background and preserves the original goal: HDR turns on before the game, then off automatically after exit.
Notes
- This script relies on the Windows HDR keyboard shortcut (
Win + Alt + B). - is most effective on single-monitor HDR setups; multi-monitor setups may need custom tuning.